簡體   English   中英

如何以編程方式更改選項卡欄 Controller 的項目圖像

[英]How to change the item image of the Tab Bar Controller programmatically

我從主文件 (XCode 14.1) 中手動添加了一個標簽欄 Controller。 我認為這是主要的 storyboard

在此處輸入圖像描述

兩個項目場景都有自己的 controller class(自定義類)。

在任一 class 中,我想更改項目圖像和標題。 對於這個問題,圖片。 對應場景class里面的其中一個(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")

}

我想以編程方式更改其中一個選項卡的圖像,我從外部獲取圖像。

您正在錯誤地創建圖像。 要使用您需要使用的 SF 符號之一:

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

使用UImage(named:)嘗試從您的資源包或圖像資產中加載圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM