我为笔记应用程序创建了一个UITextView。我想动态地单击KeyboardButton时更改UIFont。我尝试使用此代码,但它更改了UITextView中的所有文本。我想在按下按钮后更改字体。谁能帮我吗?
func setKeyboard() {
let bar = UIToolbar()
let flex = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil)
let reset = UIBarButtonItem(image: UIImage(named: "icons8-keyboard-50")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(resetTapped))
let imageAdd = UIBarButtonItem(image: UIImage(named: "icons8-font-size-50")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(fontTapped))
let font = UIBarButtonItem(image: UIImage(named: "icons8-image-80")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(resetTapped))
bar.items = [font,flex,imageAdd,reset]
bar.sizeToFit()
writePost.inputAccessoryView = bar
}
@objc func resetTapped() {
view.endEditing(true)
}
@objc func fontTapped() {
writePost.font = UIFont.boldSystemFont(ofSize: 12)
}