[[UITabBar appearance] setBackgroundImage:[UIImage imageFromColor:[UIColor colorWithR:50 G:66 B:81] forSize:CGSizeMake(SCREEN_WIDTH, MAIN_TABBAR_HEIGHT) withCornerRadius:0]];
2、改變選中的背景(背景色)
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageFromColor:[UIColor colorWithRed:49/255.0 green:158/255.0 blue:141/255.0 alpha:1] forSize:CGSizeMake(SCREEN_WIDTH / 4, MAIN_TABBAR_HEIGHT) withCornerRadius:0]];
3、改變默認的圖片的前景色
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
注:此方法會導致所有顏色,或者說所有非透明的地方都變成設置的顏色。
而當設置tabbaritem的image選項的時候,如果使用
controller.tabbaritem.image = [[UIImage imageNamed:@"tabbar_item_group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
這樣的話,setTintColor 是不起作用的。
4、設置選中的圖片的前景色
[[UITabBar appearance] setSelectedImageTintColor:MAIN_COLOR];
注:此方法會導致所有顏色,或者說所有非透明的地方都變成設置的顏色。
而當設置tabbaritem的selectedimage選項的時候,如果使用
controller.tabbaritem.selectedimage = [[UIImage imageNamed:@"tabbar_item_group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
這樣的話,setSelectedImageTintColor 是不起作用的。
5、設置tabbar字體的顏色
//設置默認時的字體顏色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; //設置選中時的字體顏色 [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MAIN_COLOR, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
同理,這裏修改 NSForegroundColorAttributeName 爲 NSFontAttributeName、NSUnderlineStyleAttributeName等,可以修改這些字體不同的屬性。