How to change UISearchBar Placeholder and image tint color?

前端 未结 12 2367
暖寄归人
暖寄归人 2020-11-29 01:24

I\'ve been trying search results for hours, but I can\'t get this figured out. Perhaps it isn\'t possible. I\'m trying to change the tint color of the placeholder text and m

12条回答
  •  Happy的楠姐
    2020-11-29 02:17

    extension UISearchBar {
        var textField: UITextField? { return value(forKey: "searchField") as? UITextField }
        var placeholderLabel: UILabel? { return textField?.value(forKey: "placeholderLabel") as? UILabel }
        var icon: UIImageView? { return textField?.leftView as? UIImageView }
        var iconColor: UIColor? {
            get {
                return icon?.tintColor
            }
            set {
                icon?.image = icon?.image?.withRenderingMode(.alwaysTemplate)
                icon?.tintColor = newValue
            }
        }
    }
    

提交回复
热议问题