修改导航栏字体样式

原文链接:点击打开链接

文章来源:http://www.aichengxu.com/view/42504

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


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

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

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

//自定义标题视图

UILabel *titleLabel = [[UILabel allocinitWithFrame:CGRectMake(0020044)];

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.navigationItem setTitle:@"修改赠品详情"];

    /**

     修改导航栏字体样式

     

     - returns: <#return value description#>

     */

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];

    UIBarButtonItem * lbb = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(back)];



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章