简体   繁体   中英

how can i set the image in background of UItoolbar?

how can i set the image in background of UItoolbar? please give the answer in simple word and in sequence of steps. Thanks

Use your custom toolbar by extending UIToolBar and override drawRect method.

@interface XToolBar : UIToolbar {
}
@end 

And implementation:

@implementation XToolBar
- (void)drawRect:(CGRect)rect {
    [[UIImage imageNamed:@"hede.png"] drawInRect:rect];
}
@end
 @implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"CustomImage.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM