2015-05-07 149 views
0

在我的應用程序中有一個帶有四個選項卡的Tabbar。我將標籤欄圖標資源(50x50)添加到Images.xcassets中。但我發現,icosn的一個顯示不正確,如下圖:Tabbar圖標顯示不正確

tab bar image

- (void)customTabBarItems{ 
    self.tabBar.superview.backgroundColor = [UIColor whiteColor]; 

    NSArray *items = self.tabBar.items; 
    NSArray *normalImgs = @[@"tab_home_normal",@"tab_message_normal",@"tab_order_normal",@"tab_userCenter_normal"]; 
    NSArray *selectedImgs = @[@"tab_home_selected",@"tab_message_selected",@"tab_order_selected",@"tab_userCenter_selected"]; 

    for (NSInteger i = 0; i < items.count; i++) { 
     UITabBarItem *item = [items objectAtIndex:i]; 
     NSString *title = titleArr[i]; 
     UIImage *normalImg = [UIImage imageNamed:normalImgs[i]]; 
     UIImage *selectImg = [UIImage imageNamed:selectedImgs[i]]; 
     item.title = title; 
     if (isIOS7Later) { 
      item.image = normalImg; 
      item.selectedImage = selectImg; 
     } 
     else{ 
      [item setFinishedSelectedImage:selectImg withFinishedUnselectedImage:normalImg]; 
     } 
    } 
} 

//set tint color 

- (void)_customAppearance 
{ 
    if (isIOS7Later) 
    { 
     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO]; 
    } 

    UIColor * color = [UIColor whiteColor]; 
    NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor]; 
    [[UINavigationBar appearance] setTitleTextAttributes:dict]; 

    if (isIOS7Later) 
    { 
     [[UITabBar appearance] setTintColor:BGCOLOR(21.0, 170.0, 255.0, 1.0)]; 
    } 
    else 
    { 
     NSDictionary *textAttributesNormal = @{UITextAttributeTextColor: BGCOLOR(179, 179, 179, 1)}; 
     NSDictionary *textAttributesSelected = @{UITextAttributeTextColor:BGCOLOR(0, 154, 255, 1)}; 
     [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_select_image"]]; 
     [[UITabBarItem appearance] setTitleTextAttributes:textAttributesNormal forState:UIControlStateNormal]; 
     [[UITabBarItem appearance] setTitleTextAttributes:textAttributesSelected forState:UIControlStateSelected]; 
     [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]]; 
     [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_select_image"]]; 
    } 

    [SVProgressHUD setForegroundColor:BGCOLOR(0, 135.0, 231, 1)]; 
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack]; 
} 

//Images.xcassets 

當我改變了第一個圖標到另一個,它似乎確定,但我想用這一個:

tab image

+0

作爲未來職位的備註:正確設置代碼格式。如果你這樣做,人們會做出更好的反應。 – Peanut

+0

@steven嘗試正確發佈問題... –

+0

「HUI」白色部分是透明的還是實際上是白色的? –

回答

1

似乎問題是在色調的顏色。色調顏色會改變圖像的可見像素顏色,所以它通常用於改變透明度的圖像顏色。看起來像你的圖像沒有透明背景,所以色調使其成爲全藍色。請檢查您的圖片源。如果你的圖像是好的,另一個可能的解決方案 - 在設置圖像之前使用渲染模式:

UIImage *toSet = [yourImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
+0

謝謝,我將渲染模式更改爲圖像集中的模板圖像,但不起作用。圖像的背景是透明的。 –