对于imageWithRenderingMode方法的两种参数的使用解释
来源:互联网 发布:gta4画面优化补丁 编辑:程序博客网 时间:2024/06/06 00:20
1.现在我们拿UITabbarController举例,来验证imageWithRenderingMode:的两种不同传参方式引起的最终效果,看如下代码:
UITabBarController *tabbarCon = [[UITabBarController alloc]init];tabbarCon.tabBar.barTintColor = [UIColor colorWithHex:0xEFF0DB alpha:0.5];tabbarCon.delegate = self;MainViewController *firstView = [[MainViewController alloc]init];UINavigationController *navigation1 = [[UINavigationController alloc]initWithRootViewController:firstView];ContactViewController *secondView = [[ContactViewController alloc]init];UINavigationController *navigation2 = [[UINavigationController alloc]initWithRootViewController:secondView];
2.这里创建了两个tabbarItem:
UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"tabbar_home_f"] selectedImage:[UIImage imageNamed:@"tabbar_home"]];navigation1.tabBarItem = item1;UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"联系方式" image:[UIImage imageNamed:@"tabbar_contact_us"] selectedImage:[UIImage imageNamed:@"tabbar_contact_us_f"]];navigation2.tabBarItem = item2;
3.如果此时我们不做其他操作,直接将两个navigationController添加到tabbarController上面:
tabbarCon.viewControllers = @[navigation1,navigation2];[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor]} forState:UIControlStateNormal];[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor orangeColor]} forState:UIControlStateSelected];self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];self.window.rootViewController = tabbarCon;[self.window makeKeyAndVisible];return YES;
4.接下来看效果,图一:
5.而我的原始图片是这样的,图二:
6.可见此时- (instancetype)initWithTitle:(nullable NSString )title image:(nullable UIImage )image selectedImage:(nullable UIImage *)selectedImage方法只是将图片依据图片模版渲染了出来,然而并没有渲染颜色。那么我们再在初始化后加上如下代码:
navigation1.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];navigation1.tabBarItem.image = [[UIImage imageNamed:@"tabbar_home_f"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];navigation2.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_contact_us"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];navigation2.tabBarItem.image = [[UIImage imageNamed:@"tabbar_contact_us_f"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
7.此时我们再看结果,图三:
8.好了,此时图片的颜色加上了,不再只是个模型了。
9.之后我们再将上面的UIImageRenderingModeAlwaysOriginal修改为UIImageRenderingModeAlwaysTemplate,再次运行,我们发现结果又如图一那样了。由此我们得出,- (instancetype)initWithTitle:(nullable NSString )title image:(nullable UIImage )image selectedImage:(nullable UIImage *)selectedImage只是将原图模版不加颜色的渲染出来。
再查看源码中的注释:
对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,意味着将图像绘制为模板图像,忽略颜色的渲染。
- 对于imageWithRenderingMode方法的两种参数的使用解释
- 对于分页的两种方法
- 对于多编程的两种方法
- 使用getParameterValues方法接收参数的两种方法
- ThreadPoolExecutor方法参数的解释
- iOS Swift 和 Objective-c 两种语言对于多线程的详细解释
- C语言编程中对于函数参数的一些解释?
- MyBatis接受参数的两种方法
- Jmeter参数化的两种方法
- ashx获取两种参数的方法
- C++可变参数的两种方法
- iOS设置tabbar的显示之 imageWithRenderingMode:
- 对于参数个数不确定的方法简介
- 对于携带请求参数的HttpGet与的HttpPost两种请求方式,代码段分析
- 在URL中传带百分号%的参数的两种方法:直接传编码或使用encodeURI
- 对于多线程两种方式的理解
- 对于高内聚低耦合的解释
- 对于setbuf函数的解释
- 数据操作string
- leetcode-question125
- 配置系统初始化失败0 x84b10001当在Windows上安装SQL Server
- 键的命令
- python 处理XML转为json
- 对于imageWithRenderingMode方法的两种参数的使用解释
- hash
- 微信小程序解决多个视频播放的问题
- list
- Docker思维导图
- 问题 C: 查找学生信息
- 简单递推
- py文件如何加密为pyc文件
- ab压力测试工具简单使用