Joey J
Joey J

Reputation: 1365

Why is this bar button black and not clear?

I'm trying to set the tintColor of a UIBarButtonItem in method that gets called when my program starts. I set up all my views using storyboards. I then customize the appearance of the views using the new iOS5 guidelines for using appearance proxies. I've customized the background of the navigation bar by doing the following:

- (void)customizeAppearance
{
    UIImage *leatherTexture = [[UIImage imageNamed:@"[email protected]"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    [[UINavigationBar appearance] setBackgroundImage:leatherTexture
                                       forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:leatherTexture
                                       forBarMetrics:UIBarMetricsLandscapePhone];

    [[UIBarButtonItem appearance] setTintColor:[UIColor clearColor]];
}

I was hoping that by setting the UIBarButtonItem tintColor to clear would allow me to easily use the default button styles while having a custom background texture. However, setting the tintColor to clear just turns the button black as opposed to being transparent or clear. Any ideas what I'm doing wrong? Is there a way to create a clear button without having to use custom images for the buttons? See the image below:

bar

Upvotes: 1

Views: 1035

Answers (2)

Obiwahn
Obiwahn

Reputation: 3087

Just found out that in Xcode 4.5 you can just drag a UIButton into the UIBarButton in the Storyboard. The UIButton is then fully customizable.

Upvotes: 1

Adil Soomro
Adil Soomro

Reputation: 37729

You can't do this way (because IMO the default background of UIBarButtonItem is black. and new tint color is over-layered on it).

However you can customize your UIBarButtonItem with using UIButton (with background) as customView in UIBarButtonItem.

Or if you are targeting iOS 5 only you can use brown tint color (which will be flat and will not show background image)

Upvotes: 1

Related Questions