[翻译] DFXCoreTextView

[翻译] DFXCoreTextView

DFXCoreTextView

https://github.com/davefoxy/DFXCoreTextView

A 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 使用。

[翻译] DFXCoreTextView [翻译] DFXCoreTextView

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 to declare 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 properties are 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.4

DFXCoreTextView 使用 ARC,以及一些“最新OC”特性如  auto-synthesize 需要 Xcode 4.4。

上一篇:"undefined reference to" 问题解决方法 -链接问题


下一篇:cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第0步---知识点总结&效果预览&设计思路