确认按钮改用 iOS 26 原生 Liquid Glass API

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 21:52:07 +08:00
parent 711693f09a
commit 8f2152dc18
@@ -61,27 +61,16 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
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 glassButton = UIButton(type: .custom) var glassConfig = UIButton.Configuration.glass()
glassButton.layer.cornerRadius = 14 glassConfig.title = "确认"
glassButton.layer.borderWidth = 0.5 glassConfig.cornerStyle = .fixed
glassButton.layer.borderColor = UIColor(white: 1, alpha: 0.6).cgColor glassConfig.baseForegroundColor = .white
glassButton.clipsToBounds = true glassConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 60, height: 44)) outgoing.font = .systemFont(ofSize: 16, weight: .semibold)
let bgImage = renderer.image { ctx in return outgoing
let gradient = CGGradient(
colorsSpace: CGColorSpaceCreateDeviceRGB(),
colors: [UIColor(red: 0.6, green: 0.75, blue: 0.95, alpha: 0.7).cgColor, UIColor(red: 0.3, green: 0.55, blue: 0.85, alpha: 0.45).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) let glassButton = UIButton(configuration: glassConfig)
glassButton.setTitle("确认", for: .normal)
glassButton.setTitleColor(.white, for: .normal)
glassButton.titleLabel?.font = .systemFont(ofSize: 16, weight: .semibold)
glassButton.addAction(UIAction { [weak self] _ in glassButton.addAction(UIAction { [weak self] _ in
self?.onSubmit?() self?.onSubmit?()
}, for: .touchUpInside) }, for: .touchUpInside)