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

 

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。

最新文章

  1. js获取页面宽度高度及屏幕分辨率
  2. phantomjs 另类用法
  3. Get function name by address in Linux
  4. 去除html标签 正则 <.+?> 解释
  5. Linux的关机与重启命令
  6. 当list中有中文,打印的时候显示为字符编码的问题
  7. vim编程配置方法
  8. weui.css中flex容器下子项目的水平和垂直居中
  9. 使用SSH框架查出的实体集合用AJAX形式刷新到页面JOSONArray报异常
  10. insert ,update 以及merge 的使用
  11. element-ui 动态换肤
  12. 初识springboot(傻瓜式教程)
  13. MongoDB Export & Import
  14. JavaScript并发模型与Event Loop (转载)
  15. SCF: 简单配置门面[转]
  16. C#搭建CEF(CEFGLUE) 环境。
  17. 编程实现Linux系统的od功能
  18. APP-8-文本语音
  19. js ajax 数据获取
  20. Python3基础 str format 四舍六入五凑偶 保留一位小数

热门文章

  1. Ansible实战:部署分布式日志系统
  2. javascript json字符串转json对象方法
  3. linux 101 hacks 2date,grep,find
  4. Web前端开发最佳实践(11):使用更严格的JavaScript编码方式,提高代码质量
  5. Web前端开发最佳实践(7):使用合理的技术方案来构建小图标
  6. codeforces 354 D. Transferring Pyramid
  7. XUtils开源框架的使用(HttpUtils支持多线程断点续传)
  8. HTTP.Socket.TCP详解
  9. 全链路压测平台(Quake)在美团中的实践
  10. Python2字符编码问题汇总