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. 更新svn的客户端TortoiseSVN后 ,之前使用svn管理的文件的关联图标消失了

    说明:下面的解决方法及图片来自博客:装了SVN,你的关联图标变了没有? 解决办法:在同步的文件点击右键如下图   ...       现则Settings,出现的界面如下 ...            ...

  2. CentOS7多实例安装mysq5.6二进制版本

    1丶下载mysql,解压,创建用户,创建软链接 test -d /tools || mkdir /tools ;cd /tools wget http://mirrors.sohu.com/mysql ...

  3. hdoj1233 还是畅通工程(Prime || Kruskal)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1233 思路 最小生成树问题,使用Prime算法或者Kruskal算法解决. 代码 Prime算法: # ...

  4. linux 添加samba账户

    1.adduser kilen   添加linux账户 2.cd /etc/samba/ 当前目录下修改smb.conf 文件 ,一般情况下是只读文件,需要修改权下 (用root用户) chmod 7 ...

  5. -bash: sdk: command not found

    Mac上安装过sdkman 但是由于某种原因使环境变量丢失久会出现使用sdk命令时 出现-bash: sdk: command not found提示 从新按照教程安装又提示电脑上sdkman已经安装 ...

  6. 「长乐集训 2017 Day10」划分序列 (二分 dp)

    「长乐集训 2017 Day10」划分序列 题目描述 给定一个长度为 n nn 的序列 Ai A_iA​i​​,现在要求把这个序列分成恰好 K KK 段,(每一段是一个连续子序列,且每个元素恰好属于一 ...

  7. (三)宏 __cplusplus C/C++混合编程

    前面一些篇目的内容作为一个在校生,很少用到,可能工作的人会见得多一点,但是第一次整体性的学习还是不希望有落下的东西,虽然不常用但至少要有个印象 那么就进入第三篇<宏 __cplusplus> ...

  8. 【SQL】185. Department Top Three Salaries

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  9. 【Vijos 1998】【SDOI 2016】平凡的骰子

    https://vijos.org/p/1998 三维计算几何. 需要混合积求四面体体积: 四面体剖分后合并带权重心求总重心: 四面体重心的横纵坐标是四个顶点的横纵坐标的平均数: 三维差积求平面的法向 ...

  10. mysql_connect的$new_link参数

    假设在127.0.0.1上有test1和test2两个库, 其中库test1库中有test1表,test2中有test2表 $servername = "127.0.0.1"; $ ...