//設(shè)置tabBar的背景顏色,使用的方法
-(void)insertSubview:(UIView*)viewatIndex:(NSInteger)index;
//設(shè)置tabbar的背景
UIView*tabbarBgView =[[UIViewalloc]initWithFrame:CGRectMake(0,0,self.tabBar.frame.size.width,self.tabBar.frame.size.height)];
tabbarBgView.backgroundColor=kAppBarColor;
[self.tabBarinsertSubview:tabbarBgViewatIndex:0];
//tabbar被選中的背景顏色
CGSizeindicatorImageSize=CGSizeMake(self.tabBar.bounds.size.width/5-10,self.tabBar.bounds.size.height);
self.tabBar.selectionIndicatorImage=[selfdrawTabBarItemBackgroundUmageWithSize:indicatorImageSize];
//字體大小记焊,顏色(未被選中時)
[[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:kAppWhiteColor,NSForegroundColorAttributeName,[UIFontfontWithName:@"Helvetica"size:12.0f],NSFontAttributeName,nil]forState:UIControlStateNormal];
//字體大小栓撞,顏色(被選中時)
[[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:kAppNavigationBarColor,NSForegroundColorAttributeName,[UIFontfontWithName:@"Helvetica"size:12.0f],NSFontAttributeName,nil]forState:UIControlStateSelected];
//繪制圖片
-(UIImage*)drawTabBarItemBackgroundUmageWithSize:(CGSize)size
{
//開始圖形上下文
UIGraphicsBeginImageContext(size);
//獲得圖形上下文
CGContextRefctx=UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(ctx,1,1,1,1);
CGContextFillRect(ctx,CGRectMake(5,0,size.width,size.height));
CGRectrect=CGRectMake(0,0,size.width,size.height);
CGContextAddEllipseInRect(ctx, rect);
CGContextClip(ctx);
UIImage*image=UIGraphicsGetImageFromCurrentImageContext();
[imagedrawInRect:rect];
UIGraphicsEndImageContext();
returnimage;
}
//tabBar和navigationBar結(jié)合使用
UIViewController *vc= [UIViewControllernew];
UINavigationController*nav =[[UINavigationControlleralloc]initWithRootViewController:vc];
vc.tabBarItem.title=@"首頁";
//設(shè)置tabbar被選中與未被選中的圖片
nav.tabBarItem.image=[[UIImageimageNamed:@"home_btn"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav.tabBarItem.selectedImage=[[UIImageimageNamed:@"home_btn02"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
//設(shè)置navigationbar的顏色
[nav.navigationBarsetBarTintColor:kAppNavigationBarColor];
//或設(shè)置navigationbar的背景圖片
[nav.navigationBarsetBackgroundImage:navBarBackgroundImageforBarMetrics:UIBarMetricsDefault];