Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UIToolbar have a Clear Background?

I have a UIToolbar that has a white tint, with a bar button item, followed by some flexible space, followed by another bar button item. I would like to make the toolbar completely clear so that I can see what is under the flexible space (I don't care about seeing what is behind the buttons). Is there a way to do this? I have tried setting the toolbar to translucent, but that does not make it completely clear.

like image 979
Kyle Rosenbluth Avatar asked Aug 21 '12 15:08

Kyle Rosenbluth


5 Answers

[self.toolbar setBackgroundImage:[UIImage new]
              forToolbarPosition:UIToolbarPositionAny
                      barMetrics:UIBarMetricsDefault];

 [self.toolbar setBackgroundColor:[UIColor clearColor]];
like image 143
Ievgen Avatar answered Oct 05 '22 17:10

Ievgen


Subclass UIToolbar, and implement the below method:

- (void)drawRect:(CGRect)rect 
{
  [[UIColor colorWithWhite:0 alpha:0.6f] set]; // or clearColor etc
  CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
}

see more details here

like image 39
Shamsudheen TK Avatar answered Oct 05 '22 19:10

Shamsudheen TK


set toolbarStyle -1 like this

 tools.barStyle = -1; // clear background
like image 40
NANNAV Avatar answered Oct 05 '22 17:10

NANNAV


Hacky, sorry, but the only way I've found so far that reliably works in both iOS 7 and iOS 6 is to do this:

[[toolbar.subviews objectAtIndex:0] removeFromSuperview];
like image 31
Danyal Aytekin Avatar answered Oct 05 '22 18:10

Danyal Aytekin


If you want a global solution take advantage of the UIAppearance proxy:

UIToolbar *toolbarAppearance = [UIToolbar appearance]; [toolbarAppearance setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

like image 1
Adam Waite Avatar answered Oct 05 '22 19:10

Adam Waite