美文网首页
YYTextView跟IQKeyboradManager

YYTextView跟IQKeyboradManager

作者: 太平洋_cfd2 | 来源:发表于2022-09-22 14:09 被阅读0次

extension YYTextView {

func getToolbar() -> IQToolbar {
    
    let toolbar = self.keyboardToolbar
    
    var items = [IQBarButtonItem]()
    
    do {
        //Flexible space
        items.append(self.flexibleBarButtonItem())

        //Title button
        toolbar.titleBarButton.title = self.placeholderText

        if #available(iOS 11, *) {} else {
            toolbar.titleBarButton.customView?.frame = CGRect.zero
        }

        items.append(toolbar.titleBarButton)

        //Flexible space
        items.append(self.flexibleBarButtonItem())
    }
    
    let done = toolbar.doneBarButton
    done.title = "完成"
    done.addTargetForAction(self, action: #selector(doneClick))
    items.append(done)
    toolbar.items = items
    
    return toolbar
}

private func flexibleBarButtonItem () -> IQBarButtonItem {

    struct Static {

        static let nilButton = IQBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
    }

// Static.nilButton.isSystemItem = true
return Static.nilButton
}

@objc private func doneClick() {
    UIApplication.shared.keyWindow?.endEditing(true)
}

}

相关文章

网友评论

      本文标题:YYTextView跟IQKeyboradManager

      本文链接:https://www.haomeiwen.com/subject/iwmwortx.html