1

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:@"BrownLeather@2x.png"] 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

Joey J
  • 1,355
  • 10
  • 26
  • have a look http://stackoverflow.com/questions/9138490/make-a-cleartransluscent-uibarbutttonitem-ios-5 – Anil Kothari Mar 08 '12 at 07:15
  • Anil - sorry I should have mentioned I'm using storyboards to set-up all the views. I'll add it to the post. In any case, the asker has the same frustration as I. Of course, this can be done by using custom clear button images but it would be nicer if this could be done without needing custom images. So I guess that's really my question - can it be done using storyboards and not using custom images? – Joey J Mar 08 '12 at 07:24
  • A tinted control doesn't inherit the alpha value of the tinting color. – Lily Ballard Mar 08 '12 at 07:27

2 Answers2

1

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.

Obiwahn
  • 2,677
  • 2
  • 26
  • 36
1

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)

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
  • Adil - this could work and I've seen solutions similar to it but it's not ideal because you are creating a custom UIBarButtonItem for every view controller that uses one. The idea behind the appearance proxy is so that you define a style once and have it applied to all view controllers. Do you know of a way to do what you are suggesting using appearance proxies? – Joey J Mar 08 '12 at 09:06
  • You can have look at [this post](http://stackoverflow.com/a/3095534/593709) and [this post as well](http://stackoverflow.com/q/3081203/593709) – Adil Soomro Mar 08 '12 at 09:21
  • 1
    Just to add to this answer if anyone else reads this in the future: After playing around with the different methods, the approach Adil has highlighted is absolutely correct. Unfortunately, to have a 'clear button' that shows the background behind it you do need to use use a custom image and the method that Adil has said to take. Thanks Adil! – Joey J Mar 26 '12 at 07:37