方法一:自定义视图。
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
titleLabel.backgroundColor = [UIColor grayColor];
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.textColor = [UIColor blueColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"导航栏标题";
self.navigationItem.titleView = titleLabel;方法二:在默认显示的标题中直接修改文字的大小和颜色。
self.navigationItem.title = @"导航栏标题";
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blueColor]}];
本文详细介绍了如何在iOS导航栏中自定义标题的样式,包括背景颜色、字体大小、颜色和对齐方式,通过设置titleView来实现个性化导航栏设计。

1219

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



