确认按钮改为 Liquid Glass 风格

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 21:47:22 +08:00
parent 36cb048aa1
commit 885f56218e
@@ -60,17 +60,44 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
let accessory = UIView() let accessory = UIView()
accessory.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 52) accessory.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 52)
accessory.backgroundColor = .clear accessory.backgroundColor = .clear
let confirmButton = UIButton(type: .system)
confirmButton.setTitle("确认", for: .normal) let glassButton = UIButton(type: .custom)
confirmButton.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold) glassButton.layer.cornerRadius = 14
confirmButton.addAction(UIAction { [weak self] _ in glassButton.layer.borderWidth = 0.5
glassButton.layer.borderColor = UIColor(white: 1, alpha: 0.6).cgColor
glassButton.clipsToBounds = true
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 60, height: 44))
let bgImage = renderer.image { ctx in
let gradient = CGGradient(
colorsSpace: CGColorSpaceCreateDeviceRGB(),
colors: [UIColor(white: 1, alpha: 0.65).cgColor, UIColor(white: 1, alpha: 0.2).cgColor] as CFArray,
locations: [0, 0.5]
)!
ctx.cgContext.drawLinearGradient(gradient,
start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: 44), options: [])
}
glassButton.setBackgroundImage(bgImage, for: .normal)
var titleConfig = UIButton.Configuration.plain()
titleConfig.title = "确认"
titleConfig.baseForegroundColor = .white
titleConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = .systemFont(ofSize: 16, weight: .semibold)
return outgoing
}
glassButton.configuration = titleConfig
glassButton.addAction(UIAction { [weak self] _ in
self?.onSubmit?() self?.onSubmit?()
}, for: .touchUpInside) }, for: .touchUpInside)
confirmButton.translatesAutoresizingMaskIntoConstraints = false glassButton.translatesAutoresizingMaskIntoConstraints = false
accessory.addSubview(confirmButton) accessory.addSubview(glassButton)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
confirmButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -8), glassButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -15),
confirmButton.topAnchor.constraint(equalTo: accessory.topAnchor, constant: 8) glassButton.centerYAnchor.constraint(equalTo: accessory.centerYAnchor),
glassButton.widthAnchor.constraint(equalToConstant: 60),
glassButton.heightAnchor.constraint(equalToConstant: 44)
]) ])
hiddenField.inputAccessoryView = accessory hiddenField.inputAccessoryView = accessory