2012-01-17 81 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