ios - swift : How to add icon image and image background to the UItabBar in App delegate?

标签 ios xcode swift uitabbarcontroller

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)

最佳答案

UITabBarController 项在各个 View Controller 上设置 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]

关于ios - swift : How to add icon image and image background to the UItabBar in App delegate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28823760/

相关文章:

ios - 迪尔德 : Symbol not found (Xcode 11)

swift - 将 dateFromString 转换为另一种格式 - SWIFT

swift - 在 Swift 中设置计时器

swift - 在树莓派上运行 Swift

ios - ReactiveCocoa 5 动画

ios - 如何使用换行 rune 本字段?

ios - Kiwi 单元测试在 Xcode 中从未失败

iphone - UIWebView 调整大小慢

objective-c - 如何读取框架内的资源文件?

ios - 使用检索到的核心数据