iOS常用

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

2018-04-12  本文已影响0人  沉睡的麦麦

记录一下平时工作遇到的一些小知识.

方法一:自定义视图

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]}];

上一篇 下一篇

猜你喜欢

热点阅读