update travis config
a pod to convert String to NSAttributedString
用来将包含格式化命令的纯文本字符串转换为格式字符串。主要设计用于 Label、Button 和小型文本框。大型页面可以直接使用 NSAttributedString.init(html:documentAttributes:)来实现。
NSAttributedString.init(html:documentAttributes:)
Convert a string with format commands to NSAttributedString. This is designed for Label\Button\small TextView. NSAttributedString.init(html:documentAttributes:) should be better choice for a big page.
新版实现基于MarkdownKit和iosMath实现
New 2.0 version is built based on MarkdownKit and iosMath
可以运行样例 app 来测试不同格式命令的效果。
The example project can be used to test format commands.
To run the example project, clone the repo, and run pod install from the Example directory first.
pod install
TextFormater 可通过CocoaPods安装:
TextFormater is available through CocoaPods. To install it, simply add the following line to your Podfile:
注意 iosMath 需要最新版,可使用github版本
Note New version of iosMath is required
pod 'iosMath', :git => 'https://github.com/kostub/iosMath.git' pod "TextFormater"
func getImage(byKey: String) -> UIImage? { switch byKey { case "50": return #imageLiteral(resourceName: "img50") default: return nil }
let textFormater = TextFormater() textFormater.imageDelegate = self
textResult.attributedText = textFormater.parse(textCode.text)
在创建对象时可设置字体
It is recommanded to customize fonts during init()
public init(fontFamilies:[String] = ["Verdana","苹方-简"], fontSize:CGFloat = 0, color:MarkdownColor = MarkdownParser.defaultColor, boldFontFamilies:[String] = ["Didot","Hei"], boldFontSize:CGFloat = 0, boldFontColor:MarkdownColor = MarkdownParser.defaultColor, italicFontFamilies:[String] = ["Times New Roman","Kai"], italicFontSize:CGFloat = 0, italicFontColor:MarkdownColor = MarkdownParser.defaultColor, equationFontSize:CGFloat = 0, equationColor:MarkdownColor = MarkdownParser.defaultColor, imageDelegate:GetImageForTextFormater = NilImageDelegate() )
不支持同一命令嵌套使用
It is not supported to nest same command
<br>
换行。该命令不需要结束 (</>)。
</>
New line. No closure (</>) to this command.
<img>key</img>
插入图片。
Insert an image.
<center>.*</center>
居中。自动在首尾增加两个换行(\n)
\n
Center alignment. Newline (\n) added to head and tail.
<color black|blue|red|green|yellow|...>.*</color>
设置前景色。
Set foreground color.
<bgcolor black|blue|red|green|yellow|...>.*</bgcolor>
设置背景色。
Set background color.
$equation$
行内模式数学公式。 LaTeX equation in text mode.
单行居中数学公式。 LaTeX equation in display mode.
Alfred Gao, alfredg@alfredg.cn
TextFormater is available under the MIT license. See the LICENSE file for more info.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
TextFormater
a pod to convert String to NSAttributedString
用来将包含格式化命令的纯文本字符串转换为格式字符串。主要设计用于 Label、Button 和小型文本框。大型页面可以直接使用
NSAttributedString.init(html:documentAttributes:)
来实现。Convert a string with format commands to NSAttributedString. This is designed for Label\Button\small TextView.
NSAttributedString.init(html:documentAttributes:)
should be better choice for a big page.Thanks
新版实现基于MarkdownKit和iosMath实现
New 2.0 version is built based on MarkdownKit and iosMath
Example
可以运行样例 app 来测试不同格式命令的效果。
The example project can be used to test format commands.
To run the example project, clone the repo, and run
pod install
from the Example directory first.Requirements
Installation
TextFormater 可通过CocoaPods安装:
TextFormater is available through CocoaPods. To install it, simply add the following line to your Podfile:
注意 iosMath 需要最新版,可使用github版本
Note New version of iosMath is required
Usage - 用法
Customization - 定制化
在创建对象时可设置字体
It is recommanded to customize fonts during init()
imageDelegate
Commands - 格式命令
命令嵌套 - nest
不支持同一命令嵌套使用
It is not supported to nest same command
<br>
换行。该命令不需要结束 (
</>
)。New line. No closure (
</>
) to this command.<img>key</img>
插入图片。
Insert an image.
<center>.*</center>
居中。自动在首尾增加两个换行(
\n
)Center alignment. Newline (
\n
) added to head and tail.<color black|blue|red|green|yellow|...>.*</color>
设置前景色。
Set foreground color.
<bgcolor black|blue|red|green|yellow|...>.*</bgcolor>
设置背景色。
Set background color.
$equation$
行内模式数学公式。 LaTeX equation in text mode.
$equation$
单行居中数学公式。 LaTeX equation in display mode.
Author
Alfred Gao, alfredg@alfredg.cn
License
TextFormater is available under the MIT license. See the LICENSE file for more info.