是否可以更改UISearchBar
中光标的颜色?
What you actually could do is this:
[[UITextField appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:YOUR_COLOR_HERE];
If you want different tint for the searchbar itself.
I created my own SearchController
which extends UISearchController
and used the following code to use different colors for cursor and cancel button
self.searchBar.barTintColor = UIColor.greyColor()
self.searchBar.tintColor = UIColor.greyColor()
UIBarButtonItem.appearance().tintColor = UIColor.whiteColor()
For SWIFT 5
self.searchBar.barTintColor = UIColor.gray
self.searchBar.tintColor = UIColor.gray
UIBarButtonItem.appearance().tintColor = UIColor.white
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .lightGray
This will adjust the cursor to UIColor.lightGray
without changing the cancel button color.
Unfortunately not. I would also like to use a custom font in the UISearchBar, but that's not possible either.
Although it may, somehow, be possible to override the entire UISearchBar class, Apple will not accept any apps that change their classes. If it is really necessary, then you could create your own searchbar. Seems like a lot of work for cursor color though.
This is possible in iOS 7. Simply set the tint color of your UISearchBar. So, for example, in your app delegate:
[[UISearchBar appearance] setTintColor:[UIColor redColor]];
From what I can tell, this only affects the cursor color.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.