OKSGutteredCodeView
OKSGutteredCodeView 是一个 Swift 库,它提供了一个具有左侧进行了行号自动计算的 TextView 的 UIView 子类。此视图可以像任何其他视图一样轻松初始化,也可以在 Storyboard 中通过拖拽一个 UIView 并将其类设置为 OKSGutteredTextView 来使用。
安装。
为您的项目设置 OKSGutteredCodeView 的首选方法是使用 Cocoa Pods。
pod 'OKSGutteredCodeView', '~> 0.3'
有关使用 CocoaPods 的更多信息,请参阅 cocoapods.org 的入门指南。
使用
此视图提供了几种方便的方法来自定义视图的外观,以及一个用于查看其使用的测试应用。
// set the background color of the line number gutter
func setGutterBackgroundColor(color: UIColor)
//set font color
func addFontColor(color: UIColor)
//set background color for the textview
func setTextViewBackgroundColor(color: UIColor)
//set the font for the text used in both the gutter and the textview
func setfont(font: UIFont)
//programaticly get the font set on the textview
func getFont() -> UIFont
//set the text displayed in the textview programticly
func setText(text: String)
//set attributed text in the textview
func setAttributedText(text: NSAttributedString)
//append text to the end of the text view
func appendText(text: String)
//insert text a the point the custer is currently at
func insertTextAtCurser(text: String)
//programaticly pull text in the textview
func getText() -> String
//add a toolbar to the keyboard
func addTextViewAccessoryView(toolbar: UIToolbar)
协议
OKSGutteredCodeView 还使用了一个名为 'CodeViewDelegate' 的协议来将其执行事件的有关信息传递给代理对象。以下为 CodeViewDelegate 的方法。
func textUpdated(text: String)
//This is called when ever the text is updated. This can be useful for parsing user input to
//implement your own syntax highlighting.
func keyboardWillAppear(notification: Notification)
//This is called whenever the keyboard is about to appear.
func keyboardWillHide(_ notification: Notification)
//Called when the keyboard is about to be dismissed.