Xcode Image Catalogs: Image not showing in Interfa

2019-05-04 22:03发布

问题:

So, the artist sent me a Resources.xcassets folder that I simply dragged into the project. I then jumped to interface builder, added a new UIImageView, assigned an image name from the xcassets, and to my surprise, I couldn't see the images. It shows as a blue question mark.

Notice, that the IB autocomplete is working, and when I run the application, the assets actually show up! But not in interface builder, which makes laying the assets around virtually impossible, especially with the size to fit not working...

Bug reported: 15733387

回答1:

It seems I am at fault... I created a fresh new XIB, and made sure to select device family 'iPad', and the image is now showing up properly. I didn't think that was the problem because you cannot change the device family after creating the XIB! I looked everywhere for that options, but never found it... Seeing the raw XIB files, you can do this change manually, I guess (Notice where it says ".iPad"):

<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4514" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4514" systemVersion="12F45" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">

Yeah, I actually solved it, and the problem is super crazy. The artist had set all the assets as "iPad" assets, so the Contents.json file inside the *.imageset folder was assigning the "ipad" to the images I have. I opened the json file in sublime text, and changed the "ipad" to "universal", and BOOM. I had Xcode open on the side, and the image showed up almost instantly in IB!! Like, wth...