键盘上方增加确认按钮,点击验证拼写
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import UIKit
|
||||
|
||||
final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||
var onChange: (() -> Void)?
|
||||
var onSubmit: (() -> Void)?
|
||||
|
||||
private let hiddenField = UITextField()
|
||||
private let stack = UIStackView()
|
||||
@@ -56,6 +57,23 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||
hiddenField.frame = .zero
|
||||
addSubview(hiddenField)
|
||||
|
||||
let accessory = UIView()
|
||||
accessory.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 52)
|
||||
accessory.backgroundColor = .clear
|
||||
let confirmButton = UIButton(type: .system)
|
||||
confirmButton.setTitle("确认", for: .normal)
|
||||
confirmButton.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold)
|
||||
confirmButton.addAction(UIAction { [weak self] _ in
|
||||
self?.onSubmit?()
|
||||
}, for: .touchUpInside)
|
||||
confirmButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
accessory.addSubview(confirmButton)
|
||||
NSLayoutConstraint.activate([
|
||||
confirmButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -8),
|
||||
confirmButton.topAnchor.constraint(equalTo: accessory.topAnchor, constant: 8)
|
||||
])
|
||||
hiddenField.inputAccessoryView = accessory
|
||||
|
||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reactivate)))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user