我的导航栏标题有两个词,一个词我想要蓝色,另一个词我想要白色。
反正有这样做吗?
最佳答案
一种选择是创建一个UILabel
。将其attributedText
设置为具有两种颜色的属性字符串。
然后将标签设置为视图控制器的导航项的titleView
。
将以下内容添加到视图控制器的viewDidLoad
方法中:
NSAttributedString *twoColors = ... // your two color string
UILabel *label = [[UILabel alloc] init];
label.attributedText = twoColors;
[label sizeToFit];
self.navigationItem.titleView = label;