zoukankan      html  css  js  c++  java
  • 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";

  • 相关阅读:
    vs编译器好多下划波浪线但不报错
    scala学习——(1)scala基础(下)
    scala学习——(1)scala基础(上)
    未能正确加载包“Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignPackage(转)
    如何完全卸载VS2010(亲自体验过) (转)
    2_C语言中的数据类型 (十)数组
    C++ STL 学习笔记__(8)map和multimap容器
    opencv配置(转)
    2_C语言中的数据类型 (九)数组
    郑捷《机器学习算法原理与编程实践》学习笔记(第五章 梯度寻优)5.2 Logistic梯度下降法
  • 原文地址:https://www.cnblogs.com/ZGSmile/p/5719159.html
Copyright © 2011-2022 走看看