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

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

方法一:自定义视图

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。