设置TabBarItem的字体大小、颜色,各种状态下的图片

原文链接地址

- (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];

}

[self setTabBarItem:self.tabBarItem

Title:@"首页"

withTitleSize:14.0

andFoneName:@"Marion-Italic"

selectedImage:@"personal_pressed"

withTitleColor:[UIColor redColor]

unselectedImage:@"personal_pressed"

withTitleColor:[UIColor greenColor]];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容