Question

I have an iOS app compiled using the 6.1 SDK with some UIBarButtonItems where the TintColor is set programmatically in ViewWillAppear.

UIBarButtonItem leftButton = new UIBarButtonItem(...);
leftButton.TintColor = UIColor.FromRGB(231, 231, 231);

Resulting in this.

Custom UIBarButtonItem TintColor on 6.1

I've upgraded my iPhone to 7.0 but I still need to build for the 6.1 SDK for backwards device compatibility (business reasons).

When I build the app using the 6.1 SDK and run it on an iPhone running iOS 7.0, the toolbar looks like this.

Custom UIBarButtonItem TintColor on 7.0

Having read through the iOS 7 UI Transition Guide, I tried setting the UIWindow's TintColor to see if this had an effect. It did not.

On interesting thing - on this form, when I display an ActionSheet, after the ActionSheet is dismissed, the background of the Cancel and Save buttons changes from "black" to "white". I'm currently investigating why this happens.

If I can't change the TintColor programmatically under iOS 7.0 I'm thinking of creating custom background images for the buttons, like this.

Greyish Button

And use SetBackgroundImage to override the existing background.

Thanks in advance.

Update - 09.24.13

poupou's answer pointed me to the WWDC video (link) which gave me the solution at 8:37 - I need to set the navigation bar's TintColor instead of setting the specific button's TintColor.

NavigationBar.TintColor = UIColor.FromRGB(231, 231, 231);
Was it helpful?

Solution

I tried setting the UIWindow's TintColor to see if this had an effect. It did not.

It should - but if you're setting TintColor on some other UI elements then it will have priority over the one set on the main UIWindow.

There's a whole session of WWDC 2013 (session 214) about TintColor and how it works in iOS7 (that's the one with the Tic Tac Toe sample).

If you need to run/exclude some code specific to an iOS version you can do:

if (UIDevice.CurrentDevice.CheckSystemVersion (7,0)) {
    // iOS 7.0 and later
} else {
    // iOS 6.1 and earlier
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top