码迷,mamicode.com
首页 > 编程语言 > 详细

Swift开发之 使用系统的TabbarController

时间:2015-07-15 15:09:32      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

使用系统的tabbar解决图片的问题.
用sb使用系统的tabbar,弄好后发现图片始终是蓝色的,并不是原来的图片,后经上网查资料,问问同事,有了下面的这些代码,做个标记.
AppDelegate中
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
initTabBarSelectedItem()
return true
}
func initTabBarSelectedItem()
{
var rootController = self.window?.rootViewController as UITabBarController
var tabBar = rootController.tabBar

    var homeItem = tabBar.items?[0] as UITabBarItem
    var selectedImg = UIImage(named: "首页")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    if homeItem.tag == 100
    {
        homeItem.selectedImage = selectedImg
        homeItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.redColor(),NSFontAttributeName:UIFont.systemFontOfSize(14)], forState: UIControlState.Normal)
    }
    var orderItem = tabBar.items?[1] as UITabBarItem
    var orderItemImg = UIImage(named: "订单")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    if orderItem.tag == 101
    {
        orderItem.selectedImage = orderItemImg
        orderItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.redColor()], forState: UIControlState.Selected)
    }

    var releaseItem = tabBar.items?[2] as UITabBarItem
    var releaseItemImg = UIImage(named: "发布")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    if releaseItem.tag == 102
    {
        releaseItem.selectedImage = releaseItemImg
        releaseItem.image = releaseItemImg
    releaseItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.redColor()], forState: UIControlState.Selected)
    }
    var myItem = tabBar.items?[3] as UITabBarItem
    var myItemImg = UIImage(named: "我的")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    if myItem.tag == 103
    {
        myItem.selectedImage = myItemImg
        myItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.redColor()], forState: UIControlState.Selected)
    }

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Swift开发之 使用系统的TabbarController

标签:

原文地址:http://blog.csdn.net/james_johnson/article/details/46892519

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!