美文网首页
iOS 设置 UITabBarItem 选中图片的颜色和字体

iOS 设置 UITabBarItem 选中图片的颜色和字体

作者: 鹏鹏的简书 | 来源:发表于2017-11-25 15:44 被阅读12次

    - (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 = [tabbarIteminitWithTitle:titleimage:[[UIImageimageNamed:unselectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]selectedImage:[[UIImageimageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    //未选中字体颜色

    [[UITabBarItemappearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:unselectColor,NSFontAttributeName:[UIFontfontWithName:foneNamesize:size]}forState:UIControlStateNormal];

    //选中字体颜色

    [[UITabBarItemappearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:selectColor,NSFontAttributeName:[UIFontfontWithName:foneNamesize:size]}forState:UIControlStateSelected];

    }

    [selfsetTabBarItem:homeNC.tabBarItem

    Title:@"首页"

    withTitleSize:14.0

    andFoneName:@"Marion-Italic"

    selectedImage:@"orderError"

    withTitleColor:[UIColorredColor]

    unselectedImage:@"orderSuccess"

    withTitleColor:[UIColorwhiteColor]];

    相关文章

      网友评论

          本文标题:iOS 设置 UITabBarItem 选中图片的颜色和字体

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