How can I change the background image of UIToolba开发者_开发知识库r? I have been able to do this for navigation bar, but not UIToolbar. I do not want to change tintColor. I would like to change the whole image.
Thanks for your help.
From Can I give a UIToolBar a custom background in my iPhone app?
Overriding the drawRect function and creating an implementation of the UIToolbar
does the trick :)
@implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"nm010400.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
You could use the following code:
[myToolbar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolbar_40.png"]] autorelease] atIndex:0];
Fixed for Simulator 4.3.
since iOS5 you can use the Appearance API:
[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"someImage"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
精彩评论