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

标签 ios swift tabbar tabbarcontroller

我正在使用 Xcode 开发一个应用程序。我的标签栏上目前有三个 tabBarItems。我希望中间的一张是用户选择的图片。我在一个变量中有所需的图片,我设置了 tabbar.swift 来放入代码。我只需要将图像设置为具有正确大小的变量图像(并使图片显示为一个圆圈)和标题字符串的名称。 在这方面的任何帮助将不胜感激。谢谢

最佳答案

试试这段代码。

    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")

关于ios - 以编程方式快速更改标签栏项目图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39358782/

相关文章:

ios - 检查 Double 中的百分位值

ios - Action 表在 ipad mini 中显示不正确

Swift String 罕见崩溃

ios - TextField 的 Pickerview

ios - XCTAssertThrows 在 32 位架构上崩溃

ios - UITableView 问题(iOS)

ios - 使用 Swift 检查互联网连接

swift - 将 UIBarButton Item 的点击区域扩展到屏幕边缘

iPhone在uiviewcontroller中添加按钮

ios - 以编程方式返回选项卡栏 Controller 中的 View