zoukankan      html  css  js  c++  java
  • Swift开发之 使用系统的TabbarController

    使用系统的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) } }

  • 相关阅读:
    Python中的模块与包
    Mac eclipse找不到source的解决办法
    Git常用命令
    MiniCrowler
    九度题库(所有题目整理,适合计算机考研和面试的人用)
    gtest 安装
    计算广告的相关学习资源
    使用python pylab库 画线
    3到6年的.NETer应该掌握哪些知识?
    迭代器模式的一种应用场景以及C#对于迭代器的内置支持
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5339040.html
Copyright © 2011-2022 走看看