方法一:(自定義視圖的方法前联,一般人也會(huì)采用這樣的方式)
就是在導(dǎo)航向上添加一個(gè)titleView,可以使用一個(gè)label,再設(shè)置label的背景顏色透明直焙,字體什么的設(shè)置就很簡(jiǎn)單了徘溢。
//自定義標(biāo)題視圖
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;
方法二:(在默認(rèn)顯示的標(biāo)題中直接修改文件的大小和顏色也是可以的)
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:19],
NSForegroundColorAttributeName:[UIColor redColor]}];
//修改導(dǎo)航條背景色(紅褐色)self.navigationController.navigationBar.barTintColor = RGB(175,24,50,1.0);其中RGB為我的工程里的一個(gè)宏定義:#define RGB(r,g,b,a)? [UIColor colorWithRed:(r/255.0) green:(g/255.0) blue:(b/255.0) alpha:(a)]//修改導(dǎo)航條標(biāo)題顏色(白色)[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorwhiteColor],NSForegroundColorAttributeName,nil]];//修改導(dǎo)航條添加的按鈕(item)顏色(黃色)self.navigationController.navigationBar.tintColor = [UIColoryellowColor];