繁体   English   中英

在UITabBarController中设置选定的图像

[英]Set selected image in UITabBarController

我试图将其他图像设置为selectedImage ,我发现将此脚本放入AppDelegate中:

var tabBarController = self.window!.rootViewController as UITabBarController
let tabItems = tabBarController.tabBar.items as [UITabBarItem]

tabItems[2].selectedImage = UIImage(named: "image.png")

但这行不通。

我是否遗漏了明显的东西或犯了错误?

您可以尝试添加此行而不是tabItems [2] .selectedImage = UIImage(named:“ image.png”)

var selectedBG = UIImage(named:””)
UITabBar.appearance().selectionIndicatorImage = selectedBG

没关系,Xcode中的“选定图像”框现在可以使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM