简体   繁体   中英

XCode 8 doesn't show images in storyboard

After updating xcode all images in the storyboard appeared as question marks (as it doesn't find them). I tried to remove/add them, cleared derived data but still all image views show quesiton marks. If anyone has any idea what might be the problem ?

I had the same problem and I found out that it's because I don't have the image in the size that corresponds to the "View as" device selected in storyboard (bottom left).

If you've selected a device that needs the @2x image (example: iPhone 6s) and you only have the @3x image (as I did) you will see the question mark. If you add the size for the image that corresponds to the device size that you are using for storyboard, the image will appear in your imageView.

Basically, you want to have the image in all 3 sizes: @1x, @2x and @3x.

This is not an issue if you run your project and your image displays in simulator. Sometime is you change size classes then also this happens. for example if you are using multiple size class like wA,hA and wC,hr and you set constraints for any,any and compact,regular both and if you keep any,any selected in interfacebulder then it will show images properly but if you change it to compact,regular then it will shoe question mark because of simulated metrics's size . So, if it is not affecting output then it is not an issue!

You have to use xcassets catalog for your images:

1) Access Assets.xcassets

在此输入图像描述

2) Create new Image Set or choose from the list and update existing one

在此输入图像描述

3) Place your image variants in its @1x, @2x and @3x sizes :

在此输入图像描述

Call your image in your code like:

let image = UIImage(named: "NewImageName")

Well I was in the same situation and came to know that xcode 8 storyboard removes frames and that is why images are not showing. Therefore you have to put appropriate constraints on uiimageviews and then you have to force constraints on by writing this code.

UIImageView *uiv = [cell viewWithTag:100];
[uiv setNeedsUpdateConstraints];
[uiv setNeedsLayout];
[uiv layoutIfNeeded];

If you have only 3x images in your Assets that you want to work with and you have already Chosen the Initial Device View to some 2x device, then do the following:

  1. Open Storyboard file in Xcode 8.
  2. Go to File Inspector -> Interface Builder Document.
  3. Opens In -> Select Xcode 7.x
  4. Save & Close The Storyboard.
  5. Open storyboard again and Choose The Initial Device View To iPhone6s Plus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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