开发者

Programmatically adding an image to a UINavigationBar

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜