Search code examples
iosxamarinuiwebview

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.

Picker


Solution

  • 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.