记录一下平时工作遇到的一些小知识.
方法一:自定义视图
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]}];
网友评论