【问题标题】:How to change the item image of the Tab Bar Controller programmatically如何以编程方式更改选项卡栏控制器的项目图像
【发布时间】:2022-11-14 03:49:44
【问题描述】:

我从主文件 (XCode 14.1) 中手动添加了一个选项卡栏控制器。我认为这是主要故事板

两个项目场景都有自己的控制器类(自定义类)。

在任一类中,我都想更改项目图像和标题。对于这个问题,图像。在相应的场景类(ProfileViewController)之一内部:


override func viewDidLoad() {
   super.viewDidLoad()
   
   // Does nothing (both)
  self.tabBarController?.tabBar.items![1].image = UIImage(named: "square.and.arrow.up.circle")

  self.tabBarItem.image = UIImage(named: "square.and.arrow.up.circle")

}

我想以编程方式更改图像,因为对于其中一个选项卡,我从外部获取图像。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    您创建的图像不正确。要使用您需要使用的 SF 符号之一:

    UIImage(systemName: "square.and.arrow.up.circle")
    

    使用UImage(named:) 会尝试从您的资源包或图像资产中加载图像。

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-14
      • 2014-11-12
      相关资源
      最近更新 更多