【问题标题】:Swift : How to add icon image and image background to the UItabBar in App delegate?Swift:如何在 App 委托中向 UItabBar 添加图标图像和图像背景?
【发布时间】:2015-05-03 15:06:24
【问题描述】:
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

var nav1 = UINavigationController()
var first = ViewController(nibName: nil, bundle: nil)
nav1.viewControllers = [first]

var second = ccDiscovery(nibName: nil, bundle: nil)
var nav2 = UINavigationController()
nav2.viewControllers = [second]

var third = ccPosting(nibName: nil, bundle: nil)
var nav3 = UINavigationController()
nav3.viewControllers = [third]

var fourth = ccProfile(nibName: nil, bundle: nil)
var nav4 = UINavigationController()
nav4.viewControllers = [fourth]

var tabs = UITabBarController()
tabs.viewControllers = [nav1, nav2,nav3,nav4]

self.window!.rootViewController = tabs;
self.window?.makeKeyAndVisible();

如何在 App delegate 中为UItabBar 添加图标图像和图像背景?我找不到。

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.magentaColor()], forState:.Normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState:.Selected)

【问题讨论】:

    标签: ios xcode swift uitabbarcontroller


    【解决方案1】:

    UITabBarController 项目在各个视图控制器上设置tabBarItem 属性:

    var tabs = UITabBarController()
    nav1.tabBarItem.image = UIImage(named: "some-image-1")
    nav2.tabBarItem.image = UIImage(named: "some-image-2")
    nav3.tabBarItem.image = UIImage(named: "some-image-3")
    nav4.tabBarItem.image = UIImage(named: "some-image-4")
    tabs.viewControllers = [nav1, nav2, nav3, nav4]
    

    【讨论】:

      猜你喜欢
      • 2013-09-06
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多