以编程方式将图像添加到UINavigationBar

时间:2010-11-06 17:55:36

标签: iphone uinavigationbar

我有一个以编程方式实例化的UINavigationController。 有没有办法将背景设置为图像(如何在许多网站上完成)而不是标准文本。

我通过重写GRect找到了一些代码,但它被称为

-(void)drawRect:(CGRect)rect {

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

1 个答案:

答案 0 :(得分:2)

在根视图控制器的.m文件中定义你的-drawRect:这样的定义:

@implementation UINavigationBar (CustomImage)

-(void)drawRect:(CGRect)rect {

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

@end