导航栏自定义标题视图

在导航栏中添加标题很简单:

 

self.title = @"Hi all, Have A Good Day!";

 

但是如果标题太长,后半部分就变成省略号了:



 

那么,就要实现自定义标题视图:

 

UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 200, 20)];
titleText.backgroundColor = [UIColor clearColor];
[titleText setFont:[UIFont boldSystemFontOfSize:16.0]];
[titleText setTextColor:[UIColor whiteColor]];
[titleText setTextAlignment:UITextAlignmentCenter];
[titleText setText:@"Hi all, Have A Good Day!"];
self.navigationItem.titleView = titleText;
[titleText release];

 

示例图:


你可能感兴趣的:(ios,iPhone,自定义标题,导航栏)