在你要写navigation bar的m文件前面放一段这个:
@interface UINavigationBar (MyCustomNavBar) @end @implementation UINavigationBar (MyCustomNavBar) - (void) drawRect:(CGRect)rect { UIImage *barImage = [UIImage imageNamed:@"xxxxx.png"]; [barImage drawInRect:rect]; } @end
导航栏添加自定义标题(navigationItem添加标题视图)
在开发中经常会用到导航器,在导航器中添加标题很简单,如下:
self.title=@"Elimination phase Day 1";
但是如果题目太长,后半部分就变成省略号了,那要实现自定义字体,代码和效果如下:
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 200, 20)]; titleText.backgroundColor = [UIColor clearColor]; [titleText setFont:[UIFont systemFontOfSize:15.0]]; [titleText setText:@"Elimination phase Day 1"]; self.navigationItem.titleView=titleText; [titleText release];