确认按钮改为 Liquid Glass 风格
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -60,17 +60,44 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||
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
|
||||
|
||||
let glassButton = UIButton(type: .custom)
|
||||
glassButton.layer.cornerRadius = 14
|
||||
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?()
|
||||
}, for: .touchUpInside)
|
||||
confirmButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
accessory.addSubview(confirmButton)
|
||||
glassButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
accessory.addSubview(glassButton)
|
||||
NSLayoutConstraint.activate([
|
||||
confirmButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -8),
|
||||
confirmButton.topAnchor.constraint(equalTo: accessory.topAnchor, constant: 8)
|
||||
glassButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -15),
|
||||
glassButton.centerYAnchor.constraint(equalTo: accessory.centerYAnchor),
|
||||
glassButton.widthAnchor.constraint(equalToConstant: 60),
|
||||
glassButton.heightAnchor.constraint(equalToConstant: 44)
|
||||
])
|
||||
hiddenField.inputAccessoryView = accessory
|
||||
|
||||
|
||||
Reference in New Issue
Block a user