开发者

Programmatically adding an image to a UINavigationBar

开发者 https://www.devze.com 2023-01-23 15:31 出处:网络
I have a UINavigationController that I instantiated programatically. Is there a way to set the background 开发者_运维技巧to an image (how its done on many sites) instead of standard text.

I have a UINavigationController that I instantiated programatically. Is there a way to set the background 开发者_运维技巧to an image (how its done on many sites) instead of standard text.

I have found some code by overriding GRect but it ever gets called

-(void)drawRect:(CGRect)rect {

CGRect currentRect = CGRectMake(0,15,200,25);
UIImage *image = [UIImage imageNamed:@"topHeader.png"]; [image     
drawInRect:currentRect]; }


Define your -drawRect: definition like this in your root view controller's .m file:

@implementation UINavigationBar (CustomImage)

-(void)drawRect:(CGRect)rect {

CGRect currentRect = CGRectMake(0,15,200,25);
UIImage *image = [UIImage imageNamed:@"topHeader.png"]; [image     
drawInRect:currentRect]; }

@end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号