1.UITabbarItem的背景色的設(shè)置。
tabBar.tabBar.selectionIndicatorImage = [UIImage imageWithColor:[UIColor colorWithRed:0.27 green:0.73 blue:0.98 alpha:1]];
// 下面是UIImage的分類里的方法
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, Screen_Width/5, 49); //寬高 1.0只要有值就夠了
UIGraphicsBeginImageContext(rect.size); //在這個范圍內(nèi)開啟一段上下文
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);//在這段上下文中獲取到顏色UIColor
CGContextFillRect(context, rect);//用這個顏色填充這個上下文
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();//從這段上下文中獲取Image屬性,,,結(jié)束
UIGraphicsEndImageContext();
return image;
}
2.文字的設(shè)置(選中狀態(tài)和正常狀態(tài))
[viewController1.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal]; [viewController1.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateSelected];