修改导航栏中的标题的字体的颜色

2017-02-06  本文已影响59人  dslCoding

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

就是在导航向上添加一个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]}];

//修改导航条背景色(红褐色)self.navigationController.navigationBar.barTintColor = RGB(175,24,50,1.0);其中RGB为我的工程里的一个宏定义:#define RGB(r,g,b,a)  [UIColor colorWithRed:(r/255.0) green:(g/255.0) blue:(b/255.0) alpha:(a)]//修改导航条标题颜色(白色)[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorwhiteColor],NSForegroundColorAttributeName,nil]];//修改导航条添加的按钮(item)颜色(黄色)self.navigationController.navigationBar.tintColor = [UIColoryellowColor];

上一篇下一篇

猜你喜欢

热点阅读