UIImageView 并不总是为模板图像着色 [英] UIImageView doesn't always tint template image

查看:17
本文介绍了UIImageView 并不总是为模板图像着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的案例中,有两个 UIImageViews 具有相同的设置和相同的模板图像...但是一个着色图像,一个不着色

我复制了正在工作的 UIImageView 并将其放置在另一个位置上,然后它就可以工作了.这发生在我身上很多次,这个解决方案总是有效,但我仍然想知道我做错了什么?它可能是一个 Xcode 错误吗?类似的事情发生在你身上吗?我有 Xcode 8.1.

I duplicated working UIImageView and placed it instead of the other and it worked. This happened to me multiple times and this solution always worked, but I still wonder what could I have done wrong? Can it be an Xcode bug? Did something similar happen to you? I have Xcode 8.1.

推荐答案

简单的解决方案:

只需添加一个新的运行时属性,它将 UIImageView 的 tintColor 设置为指定的颜色并确保图像被着色.

Just add a new runtime attribute which will set the tintColor of the UIImageView to the specified color and ensure the image is tinted.

您仍然需要在您的 Images.xcassets 文件中将您的图像设置为模板图像.

You will still need to set your image to be rendered as a template image in your Images.xcassets file.

这样您就不需要任何额外的插座、扩展或代码行.

This way you dont need any additional outlets, extensions or lines of code.

还要注意:如果视图上的 tintColor 是相同颜色,则不会应用用户定义属性中的 tintColor,它们必须不同.

Also take note: It will not apply the tintColor in the user defined attribute if the tintColor on the view is the same color, they must be different.

这篇关于UIImageView 并不总是为模板图像着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆