2012-01-17 80 views
3

,有UI外觀,是否可以刪除漸變簡單的方法?如何刪除iOS 5中的UITabbaritem的漸變/陰影效果,iOS 5中的

我這樣做來定製我的tabbar,可以做些什麼來刪除漸變?

感謝閱讀

-(void)UIAppearances 
{ 
    //set the background of tab bar 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbar_bgrd.png"]]; 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) { 
     //iOS 5 
     //[self.tabBarController.tabBar insertSubview:imageView atIndex:1]; 

     [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_bgrd.png"]]; 
     [[UITabBar appearance] setSelectionIndicatorImage: 
     [UIImage imageNamed:@"navbaractive.png"]]; 


     [[UITabBarItem appearance] setTitleTextAttributes: 
     [NSDictionary dictionaryWithObjectsAndKeys: 
      [UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor, 
      [UIColor clearColor], UITextAttributeTextShadowColor, 
      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
      nil] forState:UIControlStateNormal]; 

     [[UITabBarItem appearance] setTitleTextAttributes: 
     [NSDictionary dictionaryWithObjectsAndKeys: 
      [UIColor whiteColor], UITextAttributeTextColor, 
      [UIColor clearColor], UITextAttributeTextShadowColor, 
      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
      nil] forState:UIControlStateSelected]; 


     //nav bar 
     [[UINavigationBar appearance] setTitleTextAttributes: 
     [NSDictionary dictionaryWithObjectsAndKeys: 
      [UIFont fontWithName:@"Rokkitt" size:28.0], 
      UITextAttributeFont, 
      nil]]; 
    } 
    else { 
     //iOS 4.whatever and below 
     [self.tabBarController.tabBar insertSubview:imageView atIndex:0]; 

    } 

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO]; 

} 

回答

4

UITabBar可以拍攝圖像,並使用其alpha通道(不透明度)建立所選擇/未選擇的圖像或採取兩種處理的圖像使用原樣。

你必須自己提供圖像到UITabBarItem與setFinishedSelectedImage:withFinishedUnselectedImage:。除了使用UITabBar的selectedImageTintColor外觀屬性更改漸變的顏色外,沒有其他方式可以影響對圖像執行的處理。

+0

你可以使用它只有ios 5和更新 – lesyk 2012-05-04 14:49:03

+0

@lesyk:正確。我鏈接到也說這個文檔,這就是爲什麼我沒有提到它。我不知道如何在iOS之前實現這一點,因爲我沒有看過它;也許你的子類UITabBar,也許你建立自己的。 – Jesper 2012-05-08 07:59:41