IOS 改变tabbar的样式

1、改变默认的背景(背景色)
[[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等,可以修改这些字体不同的属性。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章