美文网首页
设置TabBarItem的字体大小、颜色,各种状态下的图片

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

作者: Amok校长 | 来源:发表于2016-10-28 13:32 被阅读0次

    原文链接地址

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

    相关文章

      网友评论

          本文标题:设置TabBarItem的字体大小、颜色,各种状态下的图片

          本文链接:https://www.haomeiwen.com/subject/weceuttx.html