forked from organicmaps/organicmaps
[iOS] Fixed crash in UISearchBar style
This commit is contained in:
parent
ab5e0990fe
commit
17c627d701
3 changed files with 20 additions and 12 deletions
|
@ -36,6 +36,8 @@
|
|||
listener.applyTheme()
|
||||
}
|
||||
}
|
||||
|
||||
UISearchBarRenderer.setAppearance()
|
||||
}
|
||||
|
||||
private func updateView(_ view: UIView?) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class GlobalStyleSheet: IStyleSheet {
|
|||
theme.add(styleName: "SearchBar") { (s) -> (Void) in
|
||||
s.backgroundColor = colors.white
|
||||
s.barTintColor = colors.primary
|
||||
s.tintColor = colors.blackPrimaryText
|
||||
s.tintColor = UIColor.white
|
||||
s.fontColor = colors.blackSecondaryText
|
||||
}
|
||||
|
||||
|
|
|
@ -13,23 +13,29 @@ extension UISearchBar {
|
|||
class UISearchBarRenderer: UIViewRenderer {
|
||||
class func render(_ control: UISearchBar, style: Style) {
|
||||
super.render(control, style: style)
|
||||
if let backgroundColor = style.backgroundColor {
|
||||
control.searchTextField.backgroundColor = backgroundColor
|
||||
}
|
||||
if let barTintColor = style.barTintColor {
|
||||
control.barTintColor = barTintColor
|
||||
}
|
||||
if let tintColor = style.tintColor {
|
||||
control.tintColor = tintColor
|
||||
if let image = control.searchTextField.leftView as? UIImageView {
|
||||
image.tintColor = tintColor
|
||||
}
|
||||
}
|
||||
|
||||
//fix for iOS 12 and below
|
||||
class func setAppearance() {
|
||||
for style in StyleManager.shared.getStyle("SearchBar") {
|
||||
if let backgroundColor = style.backgroundColor {
|
||||
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = backgroundColor
|
||||
}
|
||||
if let tintColor = style.tintColor {
|
||||
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).leftView?.tintColor = tintColor
|
||||
}
|
||||
if let font = style.font {
|
||||
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).font = font
|
||||
}
|
||||
if let fontColor = style.fontColor {
|
||||
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).textColor = fontColor
|
||||
}
|
||||
}
|
||||
if let font = style.font {
|
||||
control.searchTextField.font = font
|
||||
}
|
||||
if let fontColor = style.fontColor {
|
||||
control.searchTextField.textColor = fontColor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue