以快速编程方式更改标签栏项目图像

以快速编程方式更改标签栏项目图像

问题描述:

我正在使用Xcode中的应用程序。我目前在我的标签栏上有三个tabBarItems。我想让中间的人成为用户选择的照片。我在变量中有所需的图片,并且我已经设置了tabbar.swift来放置代码。我只需要将图像设置为具有正确大小的变量图像(并使图片显示为一个圆圈)和标题名称转换为字符串。 任何帮助做到这一点将不胜感激。谢谢以快速编程方式更改标签栏项目图像

+0

包括你的代码,你试过的东西以及你面临的问题。 – Michael

+0

self.tabBarController?.tabBar.items![0] .image = UIImage(named:“your image name”) self.tabBarController?.tabBar.items![0] .selectedImage = UIImage(named:“your image name “) – user6520705

+0

和两个失败 – user6520705

试试这个代码。

self.tabBarController?.tabBar.items![0].image = UIImage(named: "your image name") 
    // items![0] index of your tab bar item.items![0] means tabbar first item 

    self.tabBarController?.tabBar.items![0].selectedImage = UIImage(named: "your image name") 
+0

我试过在我的tabbar.swift文件中使用此代码,但它没有做任何事情 – user6520705

+1

对不起。在度假。你正在使用自定义tabbar.swift?它将在您想要使用tabBarController引用更改图像的位置工作。 – Sofeda