iphone开发之设置UITabBar的相关属性

ios默认的样式不太适合我们的应用,可以通过一下方法设置相关属性:

设置背景:

[cpp]  view plain copy
  1. [_tabBar setBackgroundImage:[UIImage imageNamed:@"bg_tabbar"]];  

设置某个Item选中的效果:

[cpp]  view plain copy
  1. _tabBar.selectionIndicatorImage = [UIImage imageNamed:@"bar_item_selected"];//设置选中效果图片  

设置UITabBarItem文字颜色

[cpp]  view plain copy
  1. [[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor whiteColor] }  
  2.                                              forState:UIControlStateNormal];  
  3.     [[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor whiteColor] }  
  4.                                              forState:UIControlStateHighlighted];  

设置UITabBarItem未选中与选中时的图片:

[cpp]  view plain copy
  1. [_hotTabItem setFinishedSelectedImage:[UIImage imageNamed:@"1_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"1"]];  
  2.     [_searchTabItem setFinishedSelectedImage:[UIImage imageNamed:@"2_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"2"]];  
  3.     [_userTabItem setFinishedSelectedImage:[UIImage imageNamed:@"3_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"3"]];  

你可能感兴趣的:(iphone开发之设置UITabBar的相关属性)