您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 訊息 >> iOS 相關資訊

自定義UINavigationBar:修改標題顏色與字體

編輯:iOS 相關資訊

從iOS 5開始,UINavigationController可透過setTitleTextAttributes自訂navigationBar標題樣式。

例如:

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], UITextAttributeTextColor, [UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont, nil]];

其中UITextAttributeTextColor控制文字顏色,UITextAttributeFont控制字體,UITextAttributeTextShadowColor與UITextAttributeTextShadowOffset則可調整陰影效果。

實務上若要讓標題更清晰,可將字體設為系統字型並避免使用0大小,以免造成顯示異常。若App有多個導航列風格,也可在進入頁面前動態更新,以維持視覺一致性。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved