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)
}
}
网友评论