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

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

问题描述

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

我复制工作 UIImageView 并放置它而不是另一个并且它有效。这发生在我身上多次,这个解决方案总能奏效,但我仍然想知道我做错了什么?可以是xcode bug吗?发生过类似事情吗?我有Xcode 8.1。

I duplicated working UIImageViewand placed it instead of the other and it worked. This happend to me multiple times and this solution always worked, but I still wonder what could have I done wrong? Can it be xcode bug? Did something similar happend 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天全站免登陆