Search code examples
iosios5uikituitoolbar

Making UIToolBar ans UISearchBar have a matte black background


Can I do this without overriding the drawRect method?

I've tried the following:

UIImage *navBarImage = [[UIImage imageNamed:@"image_navbg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
[self.descriptionBar setBackgroundColor:[UIColor colorWithPatternImage:navBarImage]];
[self.bottomBar setBackgroundColor:[UIColor colorWithPatternImage:navBarImage]];

Where image_navbg.png is a solid matte black square. The result I get still has a black - gray gradient.

Also setting these did not help:

[self.descriptionBar setTranslucent:YES];
[self.bottomBar setTranslucent:YES];

Solution

  • If you’re targeting iOS 5, use UIAppearance for this — don’t override -drawRect: anymore.