#SHRichTextEditorTools 这是一个有助于构建富文本编辑器的扩展集合。
#安装
您可以使用基本设置并创建自己的编辑器,然后在 pod 文件中添加以下行:
pod 'SHRichTextEditorTools/Core', '~> 4.0.7'
如果您想要使用预配置的文本编辑器,您必须在 pod 文件中添加以下行:pod 'SHRichTextEditorTools/SHRichTextEditor', '~> 4.0.7'
#使用
基本
此库包含一个基本编辑器 SHRichTextEditor,包括基本功能,如 粗体
、斜体
和 缩进
特性。
let textEditor = SHRichTextEditor(textView: self.textView)
textEditor.toolBarItems = [textEditor.boldBarItem(), textEditor.italicBarItem(), textEditor.indentationBarItem()]
自定义色彩
let textEditor = SHRichTextEditor(textView: self.textView, defaultTintColor: UIColor.gray, selectedTintColor: UIColor.green)
自定义栏按钮
let boldBarItem = self.textEditor.boldBarItem(type: .title(title: "Button")) { (button, selected) in
button.barButtonItem.tintColor = selected ? UIColor.gray : UIColor.green
}
self.textEditor.toolBarItems = [boldBarItem]
在这里类型由以下枚举定义:
public enum ButtonType {
case title(title: String)
case attributed(title: String, attributes: [UIControlState.RawValue: [NSAttributedStringKey : Any]])
case image(image: UIImage)
}