Swift实战-小QQ(第3章):QQ主界面布局

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
    }

 

最终效果:

posted @ 2015-03-09 22:52  IOS小小鸟  阅读(4079)  评论(0编辑  收藏  举报