简体   繁体   中英

Change UIWebView Done button color

I am using a UIWebView to display content in an app and would like to change the color of the Done button that is displayed whenever a select control is used.

It is currently displaying as white on gray which is hard to see.

选择器

The "Done" button is white because you are probably setting the tintColor to white for all UIBarButtonItems using UIAppearance . That affects the "Done" Button in the picker view which also happens to be a UIBarButtonItem .

So you have to exclude the "Done" button in the picker view from the global white tintColor. I don't know if you only need the white UIBarButtonItems in your navigation bar, but if you do you could do this to only set the tintColor for the bar button items in your navigation bar and leave all other UIBarButtonItems untouched:

UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).tintColor = UIColor.whiteColor()

However this is only available in iOS9 and the old appearanceWhenContainedIn method that works for older iOS versions is not available in Swift.

So, if you are working with Swift and you have to target earlier iOS versions than iOS9 this is probably not working for you. In that case you have to remove the UIAppearance setting for the white tintColor and set the tintColor for the UIBarButtonItems in your navigation bar "manually" without using UIAppearance .

Another possible solution is to just do

UIPickerView.appearance().tintColor = UIColor.blueColor()

put this in your AppDelegate and you are ready to go!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM