同时设置 UINavigation 控制器的标题(color/font)(奇怪的行为)
Set title (color/font)of UINavigation controller at the same time (strange behaviour)
当我尝试在应用程序委托中自定义 UINavigation 控制器的外观时,我遇到了一些奇怪的行为。
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir Next", size: 20)!]
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor(red: 93/255, green: 173/255, blue: 173/255, alpha: 1)]
先设置颜色后字体不变,先设置字体后颜色和字体不变。但是,如果我自己设置喜欢,那么它就会改变……我似乎无法同时进行。还有其他方法吗?
你没有同时做这两件事,你正在做一个,然后用第二个替换第一个。
i=1;
后面跟i=2;
真的没什么区别。
定义:
@property(nonatomic, copy) NSDictionary *titleTextAttributes
您需要将所有属性添加到 NSDictionary
并设置 titleTextAttributes
一次。
重复两次就是在撤消第一次。你需要这样做...
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir Next", size: 20)!, NSForegroundColorAttributeName: UIColor(red: 93/255, green: 173/255, blue: 173/255, alpha: 1)]
当我尝试在应用程序委托中自定义 UINavigation 控制器的外观时,我遇到了一些奇怪的行为。
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir Next", size: 20)!]
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor(red: 93/255, green: 173/255, blue: 173/255, alpha: 1)]
先设置颜色后字体不变,先设置字体后颜色和字体不变。但是,如果我自己设置喜欢,那么它就会改变……我似乎无法同时进行。还有其他方法吗?
你没有同时做这两件事,你正在做一个,然后用第二个替换第一个。
i=1;
后面跟i=2;
真的没什么区别。
定义:
@property(nonatomic, copy) NSDictionary *titleTextAttributes
您需要将所有属性添加到 NSDictionary
并设置 titleTextAttributes
一次。
重复两次就是在撤消第一次。你需要这样做...
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir Next", size: 20)!, NSForegroundColorAttributeName: UIColor(red: 93/255, green: 173/255, blue: 173/255, alpha: 1)]