LEOTextView
LEOTextView 是一个非常高性能的富编辑器。因为它是一个 UITextView 的子类,不是 UIWebView。所有代码都是通过 TextKit 框架实现的。
功能
- 粗体文本
- 斜体文本
- 无序列表
- 有序列表
- 列表自动缩进
- 撤销和重做
- 富文本复制和粘贴
要求
Xcode 8.3 或更新版本
标签 | Swift |
---|---|
<= 0.4.x | 2.2 |
>= 0.5.0 | 3.0 |
>= 0.7.0 | 4.0 |
使用
不扩展任何类,不是 EditorController 和之类的...
您可以将 LEOTextView 放置在任何您想放的地方。
// Init TextView
let textView = LEOTextView(frame: self.view.bounds, textContainer: NSTextContainer())
// If you want to use built-in toolbar, call it.
textView.enableToolbar()
// add to View
self.view.addSubview(textView)
完成。
UITextViewDelegate
我使用了一些使用代理方法的功能,因此LEOTextView将其设置为自身代理。并为另一个代理属性提供了名为leo_delegate
的属性。
public var leo_delegate: UITextViewDelegate?
公共方法
类型转换
public func changeCurrentParagraphTextWithInputFontMode(mode: LEOInputFontMode)
public func changeSelectedTextWithInputFontMode(mode: LEOInputFontMode)
public func changeCurrentParagraphToOrderedList(orderedList isOrderedList: Bool, listPrefix: String)
文本属性持久化
通过以下方式获取JSON:
public func textAttributesJSON() -> String
此方法返回一个包含所有需要重新加载的属性的JSON字符串。
一个无序列表
- A
- B
- C
转换成JSON看起来像
{
"text": "- A\n- B\n- C",
"attributes": [
{
"location": 0,
"length": 11,
"fontType": "normal",
"name": "NSFont"
},
{
"location": 0,
"length": 11,
"listType": 3,
"name": "NSParagraphStyle"
}
]
}
通过以下方式设置JSON并显示到UITextView中:
public func setAttributeTextWithJSONString(jsonString: String)
或者只需通过以下方式设置属性
public func setAttributesWithJSONString(jsonString: String)
示例
要运行示例项目,首先从示例目录克隆仓库,然后运行pod install
。
安装
Cocoapods
LEOTextView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 文件中
pod "LEOTextView"
作者
Tuesleep, [邮箱地址保护]
许可证
LEOTextView 基于 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。