Search code examples
iosobjective-cuibarbuttonitemuiappearance

How can I set the tintColor of a UIBarButtonItem via the appearance protocol?


I'm trying to programatically set the tintColor for UIBarButtonItems throughout my project. I'm calling:

[UIBarButtonItem appearance]

However, after looking at Apple's documentation here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html

I found no such properties for setting the tintColor. The closest related methods I could find were:

setBackgroundImage:forState:barMetrics:
setBackgroundImage:forState:style:barMetrics:

However, both of these methods are for setting an actual background image. Is it not possible to simply set the button's tintColor via UIAppearance?


Solution

  • Maybe I dont understand the question correctly. But if you look in the link that you've posted, under Tasks -> Customizing Appearance, there's a property called tintColor.

    You just have to set that property to the desired color

    [[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
    

    Is this not working for you?