Swift 标签控制器(tabbar添加提醒和控制器)

 // Override point for customization after application launch.

        //初始化window 大小为设备物理大小

        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

        //window的背景颜色改成白色

        self.window?.backgroundColor = UIColor.whiteColor()

        //window作为主window显示

        self.window?.makeKeyAndVisible()

        

        /*-----------------初始化Tabbar控制器--------------*/

        let home = UIViewController()

        let message = UIViewController()

        let search = UIViewController()

        let setting = UIViewController()

        let viewControllers = [home, message, search, setting]

        

        let tabbarCtrl = UITabBarController()

        tabbarCtrl.viewControllers = viewControllers

        self.window?.rootViewController = tabbarCtrl

        

        //创建UITabBarItem

        

        //使用系统的样式创建

        let tabItem1 = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.Favorites, tag: 1)

        home.tabBarItem = tabItem1

        

        let tabItem2 = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.Bookmarks, tag: 1)

        message.tabBarItem = tabItem2

        

        //使用自定义的图片、标题

        let tabItem3 = UITabBarItem(title: "搜索", image: UIImage(named: "tabbar_discover_highlighted.png"), tag: 1)

        search.tabBarItem = tabItem3

        

        let tabItem4 = UITabBarItem(title: "设置", image: UIImage(named: "tabbar_profile_highlighted.png"), tag: 1)

        setting.tabBarItem = tabItem4

        

        /*------------------设置tabbar工具栏------------------*/

        let tabbar = tabbarCtrl.tabBar

        

        //设置tabBar的背景图片

        var img = UIImage(named: "navbg.png")

        UIGraphicsBeginImageContext(CGSizeMake(width, 49))

        img?.drawInRect(CGRectMake(0, 0, width, 49))

        img = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()

        tabbar.backgroundImage = img

        //设置tabBar的选中图片颜色

        tabbar.tintColor = UIColor.redColor()

        

        //设置选中item后,盖在此item上的图片

        tabbar.selectionIndicatorImage = UIImage(named: "选中.png")

        

        //item是指一个小图标

        tabItem1.badgeValue = "New";

转载于:https://www.cnblogs.com/ZGSmile/p/5719159.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值