UIColor(named:) always returns nil on iOS 11.0-11.2

六月ゝ 毕业季﹏ 提交于 2019-12-04 10:37:08

问题


I have a class that returns a UIColor from my custom palette. I call this programmatically but when I tested it on iOS 11 it always returns a nil result... I tried this on multiple devices and OS versions 11.0, 11.0.1, 11.2 and all of them returns nil. But as soon as I run them on >iOS 12 it always returns a correct color.

var color: UIColor? {
    switch self {
    case .darkIndigo: return UIColor(named: "darkIndigo")
    case .lightNavy: return UIColor(named: "lightNavy")
    case .cobalt: return UIColor(named: "cobalt")
    }
}

I have recently changed my bundle ID for the app... and this makes me think that it has something to do with the similar problem that UIImage has when multiple bundles are used. Especially when I get the error message

WARNING: Unable to resolve the color named "darkIndigo" from any of the following bundles:

But how is this supposed to be resolved? Should I just manually remove the whole asset catalogue and add them back?


回答1:


Edit:

This was a bug in XCode and its fixed in the new GM Seed 2 (11A420a).


I encountered this issue as well. I was using XCode 11 beta 6, with Command Line Tools 11.0.

I solved it by switching to XCode 10.2.1 and Command Line Tools 10.2.1, cleaning & building again.




回答2:


I hit this issue as well and my app uses xibs and storyboards extensively.

I was able to get around the issue by pointing Xcode beta 6 to the asset compiler (actool) from Beta 5 which I still had on my machine. You will need to link to this version (sample command: ln -s /Applications/Xcode-beta5.app/Contents/Developer/usr/bin/actool actool from within your Beta 6/7 path).

Unsure if this will cause any issue with app submission, but I confirmed that app on iOS 11 looks as it should again (light colors).



来源:https://stackoverflow.com/questions/57658176/uicolornamed-always-returns-nil-on-ios-11-0-11-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!