设置系统自带的tabbarItem!

2017-01-03  本文已影响46人  爱码师

- (void)setTabBarItem:(UITabBarItem *)tabbarItem

Title:(NSString *)title

withTitleSize:(CGFloat)size

andFoneName:(NSString *)foneName

selectedImage:(NSString *)selectedImage

withTitleColor:(UIColor *)selectColor

unselectedImage:(NSString *)unselectedImage

withTitleColor:(UIColor *)unselectColor{

//设置图片

tabbarItem = [tabbarItem initWithTitle:title image:[[UIImage imageNamed:unselectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

//未选中字体颜色

[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:unselectColor,NSFontAttributeName:[UIFont fontWithName:foneName size:size]} forState:UIControlStateNormal];

//选中字体颜色

[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:selectColor,NSFontAttributeName:[UIFont fontWithName:foneName size:size]} forState:UIControlStateSelected];

}

上一篇下一篇

猜你喜欢

热点阅读