UITabBarItem中图片和文字的设置
2016-09-23 10:22
423 查看
1、UITabBarItem中的图片在选中时,默认会被渲染为蓝色,怎样避免渲染?
(1)通过在 Images.xcassets 中选择对应的图片,然后按照下图,选择“Original Image“,即可避免该图片被渲染。
(2)通过代码来实现(推荐使用第一种方法),因为如果该图片被使用多次时,要多次通过代码来设置,而第一种方法只需要设置一次即可。
2、设置UITabBarItem中文字的字体大小和颜色
(1)通过在 Images.xcassets 中选择对应的图片,然后按照下图,选择“Original Image“,即可避免该图片被渲染。
(2)通过代码来实现(推荐使用第一种方法),因为如果该图片被使用多次时,要多次通过代码来设置,而第一种方法只需要设置一次即可。
UIImage *sltImage = [UIImage imageNamed:@"tabBar_icon"]; sltImage = [sltImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; vc.tabBarItem.selectedImage = sltImage;
2、设置UITabBarItem中文字的字体大小和颜色
// 通过appearance统一设置所有UITabBarItem的文字属性 // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置 // setTitleTextAttributes: forState: 方法后就带有UI_APPEARANCE_SELECTOR NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12]; attrs[NSForegroundColorAttributeName] = [UIColor grayColor]; NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary]; selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName]; selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor]; UITabBarItem *item = [UITabBarItem appearance]; [item setTitleTextAttributes:attrs forState:UIControlStateNormal]; [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
相关文章推荐
- 给文字、图片设置透明度(简单)
- CMS图片对应文字以及设置固定的大小
- JTextPane例子,演示为文字设置字体、字号、样式、颜色、背景色和插入图片功能
- 关于Button的认识 在button上加图片再加文字 设置圆角。
- android textview改变部分文字的颜色和string.xml中文字的替换及部分内容设置颜色、字体、超链接、图片
- NET 用户控件 文件上传,并给图片文件加水印(增加文字水印文字设置)
- VS2010解决对话框设置背景图片和文字重叠问题
- VS2010解决对话框设置背景图片和文字重叠问题
- css设置图片某个区域为文字区域(让两个div重合)
- 设置文字QT按钮包含图片与文字,以及鼠标停留备注显示,和sheetstyle风格设置。
- Firefox实现设置图片或文字内容的透明度CSS样式
- js设置图片或文字自动左右滚动控制,鼠标经过停留
- 用DIV+CSS布局中,如何设置图片与文字在同一高度?
- VS2010解决对话框设置背景图片和文字重叠问题
- 动态设置按钮上的文字和图片
- JTextPane的例子,模拟聊天客户端,演示了为每段文字设置字体、字号、样式、颜色、背景色和插入图片功能
- js设置图片或文字自动左右滚动控制,鼠标经过停留
- JTextPane例子,演示为文字设置字体、字号、样式、颜色、背景色和插入图片功能
- UIBUtton需同时设置图片和文字
- 【TabHost】Android设置TabHost文字及图片