Change background image of UIToolbar

北城以北 提交于 2019-12-04 20:24:05
visakh7

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
Warif Akhand Rishi

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!