编辑页键盘增加完成按钮
This commit is contained in:
@@ -94,6 +94,7 @@ class ClipEditViewController: UIViewController {
|
|||||||
textView.font = UIFont.preferredFont(forTextStyle: .body)
|
textView.font = UIFont.preferredFont(forTextStyle: .body)
|
||||||
textView.textContainerInset = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12)
|
textView.textContainerInset = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12)
|
||||||
textView.text = clip.text
|
textView.text = clip.text
|
||||||
|
textView.inputAccessoryView = createInputAccessoryView()
|
||||||
view.addSubview(textView)
|
view.addSubview(textView)
|
||||||
|
|
||||||
let safeArea = view.safeAreaLayoutGuide
|
let safeArea = view.safeAreaLayoutGuide
|
||||||
@@ -105,6 +106,22 @@ class ClipEditViewController: UIViewController {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func createInputAccessoryView() -> UIToolbar {
|
||||||
|
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44))
|
||||||
|
toolbar.barStyle = .default
|
||||||
|
toolbar.isTranslucent = true
|
||||||
|
|
||||||
|
let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||||
|
let doneButton = UIBarButtonItem(title: "完成", style: .done, target: self, action: #selector(didTapKeyboardDoneButton))
|
||||||
|
toolbar.items = [flexSpace, doneButton]
|
||||||
|
toolbar.sizeToFit()
|
||||||
|
return toolbar
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func didTapKeyboardDoneButton() {
|
||||||
|
textView.resignFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func didTapSaveButton() {
|
@objc private func didTapSaveButton() {
|
||||||
let updatedText = textView.text ?? ""
|
let updatedText = textView.text ?? ""
|
||||||
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
||||||
|
|||||||
Reference in New Issue
Block a user