tintColor of UIImageView doesn't work with storyboard,but work with code
Asked Answered
A

4

18

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:

Set mode

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.

imageView setting:

enter image description here

black color

Why it is black for imageView and white for button with the same setting of the image? Thanks.

Additional remarks:

When I used code to add the subview imageView,it worked well.Really werid! enter image description here

Atworth answered 7/9, 2017 at 2:21 Comment(7)
Can you share the code where you are setting the image for both the UIButton and the UIImageView?Dilapidate
@Dilapidate I didn't use code, but the storyboard. I'm sure that all the settings in the storyboard are correct. A moment ago ,I found a weird behavior that when I used the code to add the imageView, it works (change to white color). I will give a supplementary description in the question.Atworth
In that case, I'm quite certain that you might be setting the value in a wrong place in story board. Can you add the screen shots for attribute inspector for both UIButton and UIImageView?Dilapidate
@Dilapidate I have posted the screen shoot of the imageView setting in the question.You can have a look at it. Thanks.Atworth
Check out the 'Easy fix solution' here: #41121925 :)Scoutmaster
@JensSchwarzer Apple told me that it's was bug,I don't know whether it has been fixed or not.Atworth
@Atworth Sure it seems like a bug. I was just proposing a workaround until it has been fixed :)Scoutmaster
S
5

Problem still exists in Xcode 9.4.1

Setting desired color for tintColor in User Defined Runtime Attributes help me to fix this problem:

enter image description here

Sidell answered 13/9, 2018 at 13:54 Comment(3)
OK, I don't think that Apple will no longer fix the problem. I don't know why. So many people found the issue. And apple has already known it was an issue.Atworth
Thats so disappointing to have the same bug still with XCode 10.2 =(Rendarender
It still happens on iOS 11.x, but works fine on iOS 13.x. Tested with Xcode 11.3.1. I have to set alwaysTemplate and tintColor programmaticallyToggery
O
4

I set global tintColor in AppDelegate.

I was not getting proper tint color on iOS 13 Xcode 11 in dark mode. However, same image tint color appeared correct when set fora bar button.

I resolved it by setting Render As property of the image as Template Image in images.xcassets. I neither had to remove UIImageView in storyboard nor add again or adding user defined property.

Overabundance answered 3/10, 2019 at 19:2 Comment(1)
That helped me a lot. Thanks dearLimbus
Y
1

You can do that by changing the image Global tint color from the storyboard:

Global tint color

Yogini answered 24/5, 2019 at 1:5 Comment(1)
I have uninstalled the XCode for about 1.5 years, I'm not sure whether your solution works or not.Atworth
D
0

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). I was able to reproduce the problem. I tried the following and it worked.

  • Remove the UIImageView
  • Create a new UIImageView
  • Set the image and TintColor
Dilapidate answered 7/9, 2017 at 5:53 Comment(7)
Thanks,but I removed the UIImageView and created a new one,omg, my problem was still exist. I have found several weird behavior with the Xcode9 beta6.Atworth
Oh. My bad. I didn't pay attention to the fact that you're using Xcode 9. Can't say for sure then since I haven't worked with any of it's beta versionsDilapidate
Anyhow, thanks.I hope this weird issue will not happen in the released version.Atworth
Apple told me that this is a known bug.Atworth
I'm not surprisedDilapidate
And the problem still persists in XCode 9.2, and it's not the Beta version. Did they work on it before releasing the version, even after knowing it ?Radiolocation
@RaviSisodia I‘m not sure whether Apple has fixed it or not. I've already submitted the issue to Apple, they just told me it's a known issue. When I had a interview in Apple China last year, I also mentioned it.Atworth

© 2022 - 2024 — McMap. All rights reserved.