如何修改搜索框中的cancel button的颜色
// 记住最初的状态,用完的时候用这个还原
self.cancelBtnTextAttribute = UIBarButtonItem.appearance().titleTextAttributes(for: UIControlState.normal) as [String : AnyObject]?
let cancelBtn:UIButton = self.searchBar.subviews[0].subviews[2] as! UIButton
// 设置自定义的状态
cancelBtn.setTitle("取消" ,for:UIControlState.normal)
let cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: UIColor.init(hex6: 0xF24500)]
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as? [String : AnyObject], for: UIControlState.normal)
当然object-c的也是一样的实现,只要把swift的语法转换成object-c的救行了。