簡體   English   中英

iOS-標簽欄項目圖像修改

[英]IOS - tab bar item image modifications

我想將選項卡欄項目圖像的默認顏色更改為圖像的原始顏色(黑色),而不是未選擇時的灰色。

選擇后,我還想將選項卡欄項目圖像更改為填充版本。

最后一件事是位置。.似乎期望文本在其下而不會居中,如何垂直居中並可能縮小它?

我目前以這種方式設置它:

   let profileNavController = UINavigationController(rootViewController: profileController)
        profileNavController.tabBarItem.image = UIImage(named: "icon_tab_user")

這是選擇和未選擇的樣子: 在此處輸入圖片說明 在此處輸入圖片說明

從蘋果我們知道

默認情況下,實際的未選擇和選擇的圖像是根據源圖像中的alpha值自動創建的。 為防止系統變色,請為圖像提供UIImageRenderingModeAlwaysOriginal。

在這里看看。
更改標簽欄項目圖像和文本顏色iOS

我可以使用以下方法更改突出顯示和不突出顯示的圖像以及位置:

let profileNavController = UINavigationController(rootViewController: profileController)
        let profileTabBarItem  = UITabBarItem(title: nil, image: UIImage(named: "icon_tab_user")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), selectedImage: UIImage(named: "icon_tab_user_highlighted"))
        profileTabBarItem.imageInsets = UIEdgeInsetsMake(5.5, 0, -5.5, 0)
        profileNavController.tabBarItem = profileTabBarItem

暫無
暫無

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

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