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。

[翻译] DFXCoreTextView的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. Sourcetree使用 - git图形化工具(三)

    前面两个章节总结了Sourcetree的安装与配置Sourcetree密钥,这个章节主要讲如何使用Sourcetree.以前呢,都是使用git Bash进行命令行方式进行操作git,感觉部分时间浪费在 ...

  2. InstallShield在MySQL和Oracle中执行SQL脚本的方法InstallShield在MySQL和Oracle中执行SQL脚本的方法

    简述 InstallShield已经内建了对MySQL和Oracle的支持.但是这个功能是通过ODBC实现的,它对SQL脚本的格式要求非常严格,因此已经通过官方客户端测试的脚本在IS中执行时往往就会报 ...

  3. OpenCV持久化(一)

    在OpenCV中,采用FileStorage类进行数据持久化,可以采用XML或YAML格式存储数据. 将数据写入XML或YAML文件,可采用以下步骤: 1.创建FileStorage对象.可以调用构造 ...

  4. ajax传递的参数服务器端接受不到的原因

    最常见的就是组织的json数据格式有问题,尝试把单引号改为双引号试试,如下: $datares = {"uname":$uname.val(),"phone": ...

  5. jquery最精简的全选反选功能

    RT代码: function selallno(){ $('#form2 input[name=sel]:checkbox:not(:checked)').attr('checked',$('#for ...

  6. Java中面向对象的理解

    按照惯例,先做一个简单的介绍,现在开始学习 Thinging in Java 4 ,一边看,一边记录,我都不想给自己设定时间安排了,毕竟很少实现过.所以就这样吧!不定期的更新,我都会放到博客中的. 所 ...

  7. 决策树算法(ID3)

    Day Outlook Temperature Humidity Wind PlayTennis 1 Sunny Hot High Weak No 2 Sunny Hot High Strong No ...

  8. 2333: [SCOI2011]棘手的操作[我不玩了]

    2333: [SCOI2011]棘手的操作 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1979  Solved: 772[Submit][Stat ...

  9. 洛谷.3803.[模板]多项式乘法(NTT)

    题目链接:洛谷.LOJ. 为什么和那些差那么多啊.. 在这里记一下原根 Definition 阶 若\(a,p\)互质,且\(p>1\),我们称使\(a^n\equiv 1\ (mod\ p)\ ...

  10. BlocksKit(1)-基本类型的分类

    BlocksKit(1)-基本类型的分类 BlocksKit是一个用block的方式来解决我们日常用对集合对象遍历.对象快速生成使用.block作为委托对象的一种综合便利封装库.这个库主要分三个大块C ...