FK 0.1.7

FK 0.1.7

测试经过测试
语言语言 SwiftSwift
许可证 自定义
发布上次发布2015年11月
SPM支持SPM

Daniel Dahan维护。



FK 0.1.7

FK

FocusKit

文本匹配

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

FK

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