簡體   English   中英

如何更改所選標簽欄圖標的筆觸

[英]How to change stroke of selected tabbar icon

我試圖弄清楚如何更改選定的Tabbar圖標的筆觸。 其通常為青色,如所選圖標的色調。 我已經像這樣更改了所選圖標的色調和指示器圖像: self.tabBarController.tabBar.selectedImageTintColor = [UIColor grayColor]; self.tabBarController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"selectedTab.png"]; self.tabBarController.tabBar.selectedImageTintColor = [UIColor grayColor]; self.tabBarController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"selectedTab.png"];

但是現在我仍然在圖標周圍出現青色筆觸

圖片

有誰知道該代碼,因為我找不到它

我之前也注意到這一點。 我最終只是手動設置了選中和未選中的圖像,而不是讓它為我渲染顏色。

然后,您可以使用Photoshop或您喜歡的圖像編輯軟件為每個選項卡設計兩個圖像。 當選擇選項卡時,一個圖像將是選項卡圖標,而當未選擇該圖像時,另一圖像將是該選項卡圖標。 您將需要在Photoshop中自己應用色調顏色。

將所有圖像導入Xcode之后,可以將它們設置在所需的UITabBarItem上。 我通常在我的View Controllers初始化函數中進行設置。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"my-selected-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"my-deselected-icon"]];
    }
    return self;
}

您將必須對選項卡欄上的每個View Controller執行此操作。

試試下面的代碼,將其放在viewDidLoad中:

for (UITabBarItem * barItem in theTabBar.items) {
    UIImage * image = barItem.image;
    [barItem setFinishedSelectedImage:image withFinishedUnselectedImage:image];
}

暫無
暫無

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

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