NCKTextView 是一个 高性能 富文本编辑器。因为它是 UITextView 的子类,而不是 UIWebView。所有代码都是通过 TextKit 框架完成的。
Xcode 7.3 或更高版本
标签 | Swift |
---|---|
<= 0.4.x | 2.2 |
>= 0.5.0 | 3.0 |
没有扩展任何类,不是 EditorController 等等...
您可以将 NCKTextView 嵌入任何想要的地方。
// Init TextView
let textView = NCKTextView(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)
完成。
我使用的一些功能使用代理方法,因此 NCKTextView 是自我代理。并提供另一个名为 nck_delegate
的代理属性。
public var nck_delegate: UITextViewDelegate?
public func changeCurrentParagraphTextWithInputFontMode(mode: NCKInputFontMode)
public func changeSelectedTextWithInputFontMode(mode: NCKInputFontMode)
public func changeCurrentParagraphToOrderedList(orderedList isOrderedList: Bool, listPrefix: String)
通过获取 JSON
public func textAttributesJSON() -> String
此方法返回一个包含所有需要重新加载的属性的 JSON 字符串。
一个无序列表
转换为类似 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
git clone -b master https://github.com/chanricle/NCKTextView.git
Chanricle King, [email protected]
NCKTextView 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。