【发布时间】:2022-10-20 14:47:14
【问题描述】:
我正在使用UISearchBar 的外观API 自定义SwiftUI 的.searchable() 修饰符的外观。
几乎所有东西都可以,除了文本字段的字体,我不知道为什么(设置取消按钮的字体有效,或者设置文本字段的背景颜色或文本颜色也有效,所以有正确的参考) .
说话很便宜,给我看代码!
let textAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.systemBlue, // this works
.font: UIFont.boldSystemFont(ofSize: 15) // this doesnt
]
let placeholder = NSAttributedString(
string: "Search...", // this doesnt
attributes: [
.foregroundColor: UIColor.systemGray, // this works
.font: UIFont.boldSystemFont(ofSize: 15) // this doesnt
])
let textFieldAppearance = UITextField
.appearance(whenContainedInInstancesOf: [UISearchBar.self])
textFieldAppearance.backgroundColor = .red // this works
textFieldAppearance.defaultTextAttributes = textAttributes // color works, font not
textFieldAppearance.attributedPlaceholder = placeholder // color works, font or text not
我想是时候提交-radar-反馈了?
【问题讨论】:
标签: swiftui uitextfield uisearchbar searchable uisearchbartextfield