- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
/**第一种方法
*/
//自定义标题
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , 100, 44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont systemFontOfSize:15];
titleLabel.textColor = [UIColor darkGrayColor];//设置文本颜色
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.text = @"Settings";
self.navigationItem.titleView = titleLabel;
/**第二种方法
self.title = @"首页";
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
*/
NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
self.navigationController.navigationBar.titleTextAttributes = dict;
}
本文介绍两种在iOS应用中自定义导航栏标题的方法:一是通过创建UILabel并将其设置为navigationItem的titleView;二是利用navigationController的navigationBar属性来设置标题的样式。
2万+

被折叠的 条评论
为什么被折叠?



