UITabBar-UITabBarItem的选中图片未按照原图样式显示的问题mark
来源:互联网 发布:上海鲁班软件 bim 编辑:程序博客网 时间:2024/04/27 14:15
临时mark一个问题:
问题描述:
今天在写tabbarViewController时,在设置了各个controller的UITabBarItem以及tabbar的tintcolor之后,发现:
注意,我用的图是镂空的;
具体的代码如下:
UITabBarItem *conversTabBarItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"conversTabBar_N"] selectedImage:[UIImage imageNamed:@"conversTabBar_H"]];
相关影响颜色的只有tintColor的设置;
[tabBar setTintColor:APPMAINCOLOR];
它的作用是设置item的全局高亮显示,诚然他起了作用;
之所以出现这个问题,是设置在item中的图片渲染方式造成的问题;
我们看下UIImage的提供的图片表现模式的枚举:
typedef NS_ENUM(NSInteger, UIImageRenderingMode) { UIImageRenderingModeAutomatic, // Use the default rendering mode for the context where the image is used UIImageRenderingModeAlwaysOriginal, // Always draw the original image, without treating it as a template UIImageRenderingModeAlwaysTemplate, // Always draw the image as a template image, ignoring its color information} NS_ENUM_AVAILABLE_IOS(7_0);
如果不设置的话,默认就是自动处理,具体被表现的方式系统会根据上下文进行选择;
比如:
navigation bars, tab bars, toolbars, and segmented controls 对设置的图片就是采用模板的方式;
而其他的imageView和webView对图片的呈现,则是用原图的方式;
一旦设置了具体的渲染方式(姑且称作渲染),图片就会被强制按照该方式呈现;
现在,我们就明白了为什么这个图没有按照镂空的方式显示,修改代码如下:
UITabBarItem *conversTabBarItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:[[UIImage imageNamed:@"conversTabBar_N"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"conversTabBar_H"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];即强制图片按原图渲染;
效果如下:
就不感谢谁了,希望对大家有帮助吧。
0 0
- UITabBar-UITabBarItem的选中图片未按照原图样式显示的问题mark
- UITabBar的UITabBarItem图片显示不了的问题
- 关于UITabbarItem定制选中与未选中两张图片的问题
- iOS7修改UITabBar文本颜色以及解决自定义选中图片显示为默认蓝色的问题
- 关于UITabBar 显示图片的问题
- iOS开中设置UITabBar的背景图片以及各个item的选中图片和未选中
- IOS 7修改UITabbar背景图片、UITabBarItem图片以及UITabBarItem的文字颜色.
- [iOS]iOS7+ UITabBar修改选中图片显示为默认蓝色的问题解决方法,去除UITabbar顶部一像素横线
- iOS 解决UITabBarItem选中图片默认为蓝色的方法
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- OS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- ios7设置UITabbarItem的样式
- 关于UITabBarController显示,定义UITabBar的显示样式
- UITabBar 设置选中、未选中状态下title的字体颜色
- 对于UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem这几种控件的自定义
- UItabBarItem 添加图片不显示的问题解决办法
- java--事务原理
- javascript基础笔记(十五)之js的“重载”
- 01背包问题的动态规划算法、蛮力法和空间优化算法
- 总结项目中checkbox,select传值给后台
- DataTable 服务器端动态分页
- UITabBar-UITabBarItem的选中图片未按照原图样式显示的问题mark
- Could not publish server configuration for Tomcat v7.0 Server at localhost. Multiple Contexts have a
- HDU ACM 11 2094 产生冠军
- Linux命令行三:压缩 zip / 解压缩 unzip 命令
- 集合的再学习
- [暴力搜索 剪枝 约数和反函数] BZOJ 3629 [JLOI2014]聪明的燕姿
- 正解版win10下装xgboost
- emoji icon
- python快速排序算法实现