[英]Can't set my navigation bar title's font size
我試圖弄清楚如何使用StackOverflow做到這一點,並走了很遠:
[self.navController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont.systemFontSize:17 weight: UIFontWeightSemibold]}];
不幸的是,我在UIFont.systemFontSize
下划線出現錯誤,提示Bad receiver type 'CGFloat'(aka 'double')
。
如何調整我的代碼使其起作用?
您的語法已針對
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight NS_AVAILABLE_IOS(8_2);
https://developer.apple.com/documentation/uikit/uifont/1619027-systemfontofsize?language=objc
您要在此處刪除UIFont.systemFontSize
的句UIFont.systemFontSize
,而改為使用UIFont systemFontOfSize:weight:
設置屬性時,與其嘗試使所有內容都內聯,不如將它們分開可能會有所幫助,即:
UIColor *whiteColor = [UIColor whiteColor];
UIFont *navBarTitleFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightSemibold];
[self.navigationController.navigationBar setTitleTextAttributes:@{
NSForegroundColorAttributeName: whiteColor,
NSFontAttributeName: navBarTitleFont
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.