How to change the colour of the 'Cancel' button on the UISearchBar in Swift

后端 未结 12 1813
无人及你
无人及你 2020-12-29 20:28

I have added a UISearchBar to the top of my PFQueryTableViewController. I have changed the colour of the searchBar to be the colour of my app, but

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 21:05

    Base on Nick89's code , I changed like that for Swift 3.1

    let cancelButtonAttributes: [String: AnyObject] = [NSForegroundColorAttributeName: UIColor.white]
    
    UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(cancelButtonAttributes, for: .normal)
    

    I want to change on UISearchBar only instead of all UIBarButton, so I'm using like UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self])

提交回复
热议问题