Image resources (xcassets) not displayed correctly

2019-02-16 19:56发布

问题:

When I build my application on El Capitan using Xcode6.4 (Xcode7 is no option right now), all images/icons (except the AppIcon) does not show, or looks garbled.

Looking at the output from the asset compiler it looks fine, but there are two outputs I suspect could be related, but I am far from certain:

2015-10-02 12:26:53.569 ibtoold[28899:273288] NSFileCoordinator is doing nothing.

2015-10-02 12:26:54.906 ibtoold[28899:276436] CoreUI(DEBUG): CSIGenerator using 'LZFSE' Compression coreui version (362.000000)

Could it be that the LZFSE compression messes up so that Yosemite is unable to decompress correctly, and if so, is there a way to override this?

There is no problem when the application is run on El Capitan.

Any suggestions are very welcome.

UPDATE: These messages are output to console when the app runs on Yosemite:

02.10.15 22.31.59,914 AppName[452]: -[CUIThemeRendition newImageFromCSIDataSlice:ofBitmap: usingColorspace:] Unsupported pixel format in CSI got 36864

02.10.15 22.31.59,914 AppName[452]: Unable to create unsliced image from csi bitmap data.

It seems they had this problem for iOS7 in Xcode beta 3 here

But it seems strange it suddenly appeared again now, and my target is OS X.

UPDATE: So I have upgraded to Xcode7, and the whole problem disappeared. All images and Icons now show correctly in El Capitan and Yosemite.

回答1:

Background Info:

Each version of Xcode comes with a simulator built into it. Xcode 6.4 has iOS Simulator 8.4. Xcode 7.1 has iOS Simulator 9.1 etc. These simulators have profiles stored in Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/CoreSimulator/Profiles/Runtimes

When you install additional simulators, these get shared across Xcode versions, and their profiles are stored at /Library/Developer/CoreSimulator/Profiles/Runtimes

So when you install iOS Simulator 9.0 from Xcode 7.1, the 9.0 simulator profile gets put in the shared location. If you install iOS Simulator 8.4 from Xcode 7.1, it will get put here as well, as Xcode 7.1 is unaware that there is a copy of the iOS Simulator 8.4 hidden inside of Xcode 6.4.

So what appears to be happening is (for Xcode 6.4):

  • when you call actool to create an asset catalogs, it launches ibtoold
  • ibtoold calls through an XPC service (com.apple.coresimulator) and runs an instance of IBCocoaTouchImageCatalogTool on top of the simulator service
  • IBCocoaTouchImageCatalogTool goes through all of the simulator runtimes at /Library/Developer/CoreSimulator/Profiles/Runtimes and apparently uses the latest one it can find. Why it does this is not really clear to me, but no amount of knob fiddling caused it to do anything else.

So if you have Xcode 7.1.1 installed, and download the 9.0 simulator you will break your Xcode 6.4 install because the 9.0 simulator installs its runtime in the shared simulator runtime area, and Xcode 6.4 picks it up and uses it in some cases. This apparently causes actool to mangle any pngs that it is importing. In my experimentation it is fine importing jpgs. Other fun side effects include the fact that attempting to edit Storyboards in Xcode 6.4 causes Xcode 6.4 to crash.

So if you need to have both Xcode 7.x and Xcode 6.4 do NOT install any iOS 9.x simulators from the Xcode 7 installs.



回答2:

Following (partially) the advice of @drmaclach I followed these steps and got rid of those pesky -[CUIThemeRendition ...] errors (I'm using Xcode 6.4 and Mac OS X 10.11.1)

  • In Xcode, go to Window -> Projects, find your project and press the "Delete" button for "Derived Data"
  • Quit Xcode and iOS Simulator
  • delete iOS 9.0.simruntime from /Library/Developer/CoreSimulator/Profiles/Runtimes
  • Re-open project in Xcode and perform Clean Build Folder under Project when holding down option key


回答3:

Try convert .png to .jpg, my .png does not show too but .jpg is visible. Or don't put them into Images.xcassets.



回答4:

I had the same issue after installing XCode6.4. I sovled it by converting all images into .jpg for .xcassets catalog.