NCKTextView 0.5.0

NCKTextView 0.5.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2016年9月
SPM支持 SPM

chanricle 维护。



  • 作者:
  • Chanricle King

NCKTextView

codebeat badge

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)

完成。

UITextViewDelegate

我使用的一些功能使用代理方法,因此 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 字符串。

一个无序列表

  • 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

demo

安装

稳定源代码

git clone -b master https://github.com/chanricle/NCKTextView.git

作者

Chanricle King, [email protected]

许可证

NCKTextView 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。