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

来源:互联网 发布:centos apache python 编辑:程序博客网 时间:2024/05/21 08:53
- (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];}

可以用于设置TabBarItem上各种状态在显示的图片,文字的大小、颜色和字体样式。是自定义方法...

调用:

    [self setTabBarItem:homeNC.tabBarItem                  Title:@"首页"          withTitleSize:14.0            andFoneName:@"Marion-Italic"          selectedImage:@"orderError"         withTitleColor:[UIColor redColor]        unselectedImage:@"orderSuccess"         withTitleColor:[UIColor whiteColor]];

0 0
原创粉丝点击