我试图将其他图像设置为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