Files
comaps/iphone/Maps/Core/Theme/Renderers/UITextFieldRenderer.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

48 lines
1.5 KiB
Swift

extension UITextField {
@objc override func applyTheme() {
for style in StyleManager.shared.getStyle(styleName)
where !style.isEmpty && !style.hasExclusion(view: self) {
UITextFieldRenderer.render(self, style: style)
}
}
@objc override func sw_didMoveToWindow() {
guard MapsAppDelegate.theApp().window === window else {
sw_didMoveToWindow();
return
}
applyTheme()
isStyleApplied = true
sw_didMoveToWindow();
}
}
class UITextFieldRenderer {
class func render(_ control: UITextField, style: Style) {
if let cornerRadius = style.cornerRadius {
control.layer.setCornerRadius(cornerRadius)
control.clipsToBounds = true
}
control.borderStyle = .none
var placeholderAttributes = [NSAttributedString.Key : Any]()
if let backgroundColor = style.backgroundColor {
control.backgroundColor = backgroundColor
}
if let font = style.font {
control.font = font
placeholderAttributes[NSAttributedString.Key.font] = font
}
if let fontColor = style.fontColor {
control.textColor = fontColor
}
if let tintColor = style.tintColor {
control.tintColor = tintColor
placeholderAttributes[NSAttributedString.Key.foregroundColor] = tintColor
}
if let attributedPlaceholder = control.attributedPlaceholder, !attributedPlaceholder.string.isEmpty {
control.attributedPlaceholder = NSAttributedString(string: attributedPlaceholder.string,
attributes: placeholderAttributes)
}
}
}