UISearchBar cancel button color?

前端 未结 11 634
耶瑟儿~
耶瑟儿~ 2020-12-13 09:00

When I drop a UISearchBar into my view inside Interface Builder, and change its style to Black Opaque, the cancel button stays unfittingly blue / gray and doesn\'t become bl

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 09:35

    Try this and see: (I tested below code with Swift 4.1 - Xcode 9.3-beta4)

    @IBOutlet weak var sbSearchBar: UISearchBar!
    
    sbSearchBar.showsCancelButton = true
    sbSearchBar.barTintColor = UIColor.blue
    sbSearchBar.tintColor = UIColor.red
    
    if let buttonItem = sbSearchBar.subviews.first?.subviews.last as? UIButton {
        buttonItem.setTitleColor(UIColor.yellow, for: .normal)
    }
    

提交回复
热议问题