Swift- 自定義導航欄背景、標題和返回按鈕屬性
阿新 • • 發佈:2019-02-01
廢話少說,直接 看程式碼:
//navigationBar的預設背景顏色
// UINavigationBar.appearance().tintColor = UIColor(red: 0.2392, green: 0.7137, blue: 0.7451, alpha: 1)
//navigationBar的預設背景顏色
// UINavigationBar.appearance().barTintColor = UIColor(red: 0.2392, green: 0.7137, blue: 0.7451, alpha: 1)
//設定UINavigationBar title的字型和顏色
let titleTextAttributes :[String : AnyObject] = [NSFontAttributeName : UIFont(name: "Helvetica", size: 22) as! AnyObject , NSForegroundColorAttributeName : UIColor(red: 0.2392, green: 0.7137, blue: 0.7451, alpha: 1) as AnyObject]
UINavigationBar.appearance().titleTextAttributes = titleTextAttributes
//UITabBar bar 的選中顏色
UITabBar.appearance().tintColor = UIColor(red: 0.2392, green: 0.7137, blue: 0.7451, alpha: 1)
//tabbar預設的背景色
UITabBar.appearance().barTintColor = UIColor.clearColor()
關於自定義導航返回按鈕
在 appdelegate 裡面設定
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed: @"Mine_back"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"Mine_back"]];
如果控制器的導航不顯示文字
在要展示的控制器的上一個控制器新增
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@""style:UIBarButtonItemStylePlain target:self action:nil];