iOS中设置导航栏标题的字体颜色和大小

 

iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下。




在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法。

 

方法一:(自定义视图的方法,一般人也会采用这样的方式)

 

就是在导航向上添加一个titleView,可以使用一个label,再设置label的背景颜色透明,字体什么的设置就很简单了。

 

 

 

//自定义标题视图

 

UILabel *titleLabel = [[UILabel 
alloc] initWithFrame:CGRectMake(0, 
0, 200, 44)];

 

titleLabel.backgroundColor = [UIColor 
grayColor];

 

titleLabel.font = [UIFont 
boldSystemFontOfSize:20];

 

titleLabel.textColor = [UIColor 
greenColor];

 

titleLabel.textAlignment = 
NSTextAlignmentCenter;

 

titleLabel.text = 
@"新闻";

 

self.navigationItem.titleView = titleLabel;

 



 

方法二:(在默认显示的标题中直接修改文件的大小和颜色也是可以的)

 

 

 

[self.navigationController.navigationBar setTitleTextAttributes:

 

@{NSFontAttributeName:[UIFont systemFontOfSize:19],

 

NSForegroundColorAttributeName:[UIColor redColor]}];

 

方式二相对于方式一而言更加简单方便

posted @ 2016-09-01 17:28  子非余安知余子非  阅读(6019)  评论(0编辑  收藏  举报