1.導航欄外觀設定
*在AppDelegate.swift文件中的didFinishLaunchingWithOptions方法添加以下代碼
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { //.導航欄 var navBar=UINavigationBar.appearance() //.設置導航欄標題顏色 navBar.titleTextAttributes = [ NSForegroundColorAttributeName : UIColor.whiteColor()] //.設置導航欄按鈕顏色 navBar.tintColor = UIColor.whiteColor() //.設置導航欄背景顏色 navBar.barTintColor=UIColor(red: 49.0/255.0, green: 183.0/255.0, blue: 235.0/255.0, alpha: 1.0) return true }
2.讓狀態欄顯示白色
*讓launch頁面啟動時狀態欄顯示黑色
在plist文件中設定鍵:Status bar style 值:Gray style (default)
*讓App應用程序的狀態欄顯示白色
在plist文件中設定鍵:View controller-based status bar appearance 值:NO
在AppDelegate.swift文件中的didFinishLaunchingWithOptions方法添加以下代碼
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
3.建一個tabbarController 三個navigationController 三個ViewController
4.將SliderViewController文件中的initSubViews后面添加代碼:
//用mainContentView裝下MainTab var mainTabVC: UITabBarController! = self.storyboard!.instantiateViewControllerWithIdentifier("MainTabViewController") as UITabBarController mainContentView.addSubview(mainTabVC.view)
5.MessageViewController(消息),添加導航欄控件代碼:
override func viewDidLoad() { super.viewDidLoad() //左側顯示頭像 var photoView:UIImageView=UIImageView(image: UIImage(named: "AppIcon-160x60@2x.png")) photoView.frame=CGRectMake(0, 0, 30, 30) var photoItem:UIBarButtonItem=UIBarButtonItem(customView: photoView) self.navigationItem.leftBarButtonItem=photoItem //頭像變圓形(設弧度為寬度的一半) photoView.clipsToBounds=true photoView.layer.cornerRadius=photoView.bounds.width*0.5 //設置titleView為 var titleSegment=UISegmentedControl(items: ["消息", "電話"]) titleSegment.selectedSegmentIndex=0 self.navigationItem.titleView=titleSegment //左側一按鈕 var rightButton:UIButton=UIButton() rightButton.frame=CGRect(origin:CGPointZero, size: CGSize(width: 26, height: 26)) rightButton.setBackgroundImage(UIImage(named: "menu_icon_bulb.png"), forState: UIControlState.Normal); var rightItem:UIBarButtonItem=UIBarButtonItem(customView: rightButton) self.navigationItem.rightBarButtonItem=rightItem }
最終效果: