简体   繁体   中英

Xcode images visible in storyboard don't show in simulator

I'm new to xcode. I created a spritekit game with a single view controller and storyboard. After completing the game I wanted to create a new scene with image button that would open the game view.

In main.storyboard i have added a new UIViewController from the object library. I set view controller as the initial view controller. I added a button, control dragged from the button to the other view and set the action to show. When running the simulator everything worked as planned. I then tried to add an image to the button. The image shows on the view in the editor window but will not show in the simulator when set either as image or background. I then drug an image directly onto the new view controller. It shows in the editor as well but not in the simulator. I've tried using multiple different images including those that are used in the game and show on both the simulator and on a device in the game. I've tried multiple simulators with no luck. When adding the image to the button I can tell the button is not off the simulator screen because when I click the spot where the button should be it opens the other view just as it should. I've cleaned and rebuilt the project, made sure all images are in the correct folder and properly named.

It turned to be a noob issue.

All of my images were in a folder called sprites.atlas. This worked fine for my SKView but didn't work for my new UIView.

To solve the problem I:

**1. Added a new image set to Images.xcassets

  1. Added my button images to the new image set

  2. Changed the button image property to point to the image set name**

The button images now show in the sim.

For future users, this worked for me :

1) Clean the project

2) Restart Xcode

3) Run

PS If you face some new issues like random crashing then enable ARC and then keep buiding <--> fixing on a copy and then check.

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