SK 1.0.3

SK 1.0.3

测试已测试
语言语言 SwiftSwift
许可证 自定义
发布最后发布2015 年 12 月
SPM支持 SPM

Daniel Dahan 维护。



SK 1.0.3

SK

SearchKit

文本匹配

轻松匹配文本中的任何正则表达式模式。以下是一个默认哈希标签匹配的示例。

FKPreview

class NoteView: TextDelegate, TextViewDelegate {

    // ...

    lazy var text: Text = Text()
    var textView: TextView?

    // ...

    func prepareTextView() {
        let layoutManager: NSLayoutManager = NSLayoutManager()
        let textContainer = NSTextContainer(size: bounds.size)
        layoutManager.addTextContainer(textContainer)

        text.delegate = self
        text.textStorage.addLayoutManager(layoutManager)

        textView = TextView(frame: CGRectNull, textContainer: textContainer)
        textView?.delegate = self
        textView!.editable = true
        textView!.selectable = true
        textView!.font = UIFont.systemFontOfSize(16)
        textView!.text = note?["text"] as? String

        textView!.placeholderLabel = UILabel()
        textView!.placeholderLabel!.textColor = UIColor.grayColor()

        let attrText: NSMutableAttributedString = NSMutableAttributedString(string: "focus your #thoughts", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(16)])
        attrText.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: NSRange(location: 11, length: 9))
        textView!.placeholderLabel!.attributedText = attrText

        addSubview(textView!)
    }

    // ...

    func textWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange) {
        textStorage.removeAttribute(NSFontAttributeName, range: range)
        textStorage.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(16), range: range)
    }

    //...

    func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) {
        textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range)
    }

    // ...

}

许可证

AGPL-3.0