[翻译] DFXCoreTextView
2014-04-18 10:15
381 查看
DFXCoreTextView
https://github.com/davefoxy/DFXCoreTextViewA CoreText wrapper for the formatting and display of scrollable text in columns. The helper class DFXCoreTextFont is used as a replacement for UIFont, providing many formatting options only available in CoreText.
对 CoreText 的封装,以柱状的方式且可以翻动来显示文本。DFXCoreTextFont 类是用来替换 UIFont 的,提供很多的配置供 CoreText 使用。
Installation
Just drag the "DFXCoreTextView" folder inside the project directory into your own project (tick "Copy items into destination groups' folder") and add the CoreText framework to your project's build phases.把文件夹 DFXCoreTextView 拖到你的工程当中,并引入 CoreText 框架。
Usage
First, create an instance of the base view, DFXCoreTextView in either code or by setting a view inside a XIB to DFXCoreTextView. This is where all your text will be rendered. The view extends UIScrollView for pagination and scrolling however you're free todeclare yourself as it's delegate.
首先,创建一个基本 view 的实例对象,DFXCoreTextView 既可以以代码的形式,或者以 XIB 的形式添加进基本的 view 当中。在 DFXCoreTextView 中,才是你所有文本被渲染的地方。DFXCoreTextView 扩展了 UIScrollView 的翻页功能,当然,你也可以在它的代理中进行设置。
Default options are in place for presentation however, for customisation, you currently have access to the following properties on an instance:
默认的选项,就是在合适的地方显示文本,然而,为了更好的定制性,你可以控制一个实例对象的几个属性:
@property (nonatomic, assign) int columnsPerPage; @property (nonatomic, assign) CGPoint innerPadding; @property (nonatomic, assign) float columnSpacing;
When it's all set up, assign text using:
当所有的都配置好了,你就可以赋予文本了:
- (void)setText:(NSString*)text;
Formatting Using
DFXCoreTextFont
The DFXCoreTextFont class is the only way to format text or specific pieces of text in a DFXCoreTextView. It's essentially what you use instead of UIFont and it offers a few more attributes that only be achieved by using CoreText. Currently, the following propertiesare available:
DFXCoreTextFont 是唯一的你能够拿来格式化文本的类,或者对 DFXCoreTextView 中的某些文本进行格式化。其本质上是用来替换 UIFont 的,它提供了一些属性可供修改,但仅仅适用于 CoreText。目前,以下的一些属性你可以使用:
@property (nonatomic, copy) NSString *fontName; @property (nonatomic, assign) float fontSize; @property (nonatomic, assign) DFXTextAlignment textAlignment; @property (nonatomic, strong) UIColor *textColor; @property (nonatomic, strong) UIColor *strokeColor; @property (nonatomic, strong) NSNumber *strokeWidth; @property (nonatomic, assign) CGFloat lineSpacing; @property (nonatomic, assign) BOOL underlined; @property (nonatomic, assign) float kerning;
When you've created your DFXCoreTextFont instance, assign it to your text by using one of the following methods:
当你已经创建了DFXCoreTextFont 实例对象,用下面其中的一条方法来给你的文本设置字体。
- (void)setFont:(DFXCoreTextFont*)font; - (void)setFont:(DFXCoreTextFont*)font forRange:(NSRange)range; - (void)setFont:(DFXCoreTextFont*)font forOccurancesOfString:(NSString*)string comparisonMode:(DFXCTComparisonMode)comparisonMode;
Updating The View
Drawing and layout happens in drawRect: so if you're finding text not updating properly, remember to call setNeedsDisplay on your view.布局与绘图都在 drawRect:方法中进行的,所以,如果你发现你的文本没有更新属性,记住,调用 setNeedsDisplay 来重绘你的 view。
Project Requirements
DFXCoreTextView uses ARC and some elements of 'Modern Objective-C' such as auto-synthesize which requires Xcode 4.4DFXCoreTextView 使用 ARC,以及一些“最新OC”特性如 auto-synthesize 需要 Xcode 4.4。
相关文章推荐
- [翻译] DFXCoreTextView
- MAC 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(一)
- MAC OSX 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(二)
- CoreText Hyperlink View
- CoreTextHyperlinkView
- iOS开发小记:iOS富文本框架DTCoreText在UITableView上的使用
- [翻译] SAMCoreImageView
- 4.UI篇 UIKit,view与layer,frame 与bounds等 CoreText auto layout drawRect
- 在DTCoreText 中添加自定义的文章头,自定义View
- CoreText NSTextView和Attribued String
- [翻译] LazyFadeInView 渐入显示text文本
- tableview性能优化之coreText
- [翻译] DTCoreText 从HTML文档中创建富文本
- [翻译] Core Text Objective-C Wrapper
- Core Text Tutorial for iOS : Making a Magazine App 翻译
- android中使用异步调用google翻译接口翻译语句,并用译文替换显示到textView的原文
- iOS上的富文本控件-DTCoreTextView
- AutoCompleteTextView任意位置匹配
- android textview改变部分文字的颜色和string.xml中文字的替换
- 16-0 b879 1-13 TextView 设置文本颜色