简体   繁体   English

UIImageView的tintColor不适用于storyboard,但可以使用代码

[英]tintColor of UIImageView doesn't work with storyboard,but work with code

Xcode 9 beta 6,iOS 11 Xcode 9 beta 6,iOS 11

I downloaded a Instagram logo which was a .png file,and I created a UIButton and UIImageView in the Main.storyboard .The logo image was set as follows: 我下载了一个Instagram徽标,这是一个.png文件,我在Main.storyboard创建了一个UIButtonUIImageView 。徽标图像设置如下:

设置模式

And I set the TintColor of the UIButton and the UIImageView is white ,but when I run the project, the color of the image for UIImageView is still black,while white for UIButton. 我设置了UIButtonTintColor ,而UIImageViewwhite ,但是当我运行该项目时,UIImageView的图像颜色仍为黑色,而UIButton的颜色为白色。

imageView setting: imageView设置:

在此输入图像描述

黑色

Why it is black for imageView and white for button with the same setting of the image? 为什么它对于imageView是白色而对于具有相同图像设置的button是白色的? Thanks. 谢谢。

Additional remarks: 补充说明:

When I used code to add the subview imageView ,it worked well.Really werid! 当我使用的代码添加子视图imageView ,它的工作well.Really werid! 在此输入图像描述

Problem still exists in Xcode 9.4.1 问题仍存在于Xcode 9.4.1中

Setting desired color for tintColor in User Defined Runtime Attributes help me to fix this problem: 在用户定义的运行时属性中为tintColor设置所需的颜色可以帮助我解决此问题:

在此输入图像描述

Apparently there is a problem with story board where if the image view is added before adding the image in xcassets as template, the Tint Color does not take effect (if set in the storyboard). 显然故事板存在问题,如果在将xcassets中的图像添加为模板之前添加图像视图,则色调颜色不会生效(如果在故事板中设置)。 I was able to reproduce the problem. 我能够重现这个问题。 I tried the following and it worked. 我尝试了下面的工作。

  • Remove the UIImageView 删除UIImageView
  • Create a new UIImageView 创建一个新的UIImageView
  • Set the image and TintColor 设置图像和TintColor

You can do that by changing the image Global tint color from the storyboard: 您可以通过更改故事板中的图像全局色调颜色来执行此操作:

全球色调

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM