4

I'm developing a game in Swift (not Spritekit) and I'm having some difficulty creating a background image that works in every device orientation.

I see an XCode feature called asset catalog for defining the launch screen images, and I wonder if we can do something similar to define the device's background images?

Just like I said, I want to create a group of images to every device and orientation and create a image set or asset catalog, but i don't know how to do that. Has anyone here already done something like this?

*I know the concept of @2x and @3x images, but how can i implement images like that to other orientations?

Update 1: i posted one picture to help [asset catalog for Launch Screen Images[1]

Zé Moreira
  • 125
  • 1
  • 2
  • 9

2 Answers2

1

When you edit storyboard, you will see wAny hAny at the bottom. There you could choose orientation and device type. After choosing you do anything you want, and it would be only in that orientation and that device type.
Screenshot

stek29
  • 395
  • 4
  • 14
  • But i can set a specific image to a specific size class? – Zé Moreira Dec 27 '15 at 16:21
  • 1
    You can add specific ImageView for specific size class – stek29 Dec 27 '15 at 16:24
  • i already tried that, but it keeps pilling the ImageViews. For example, i create an view in the wCompact / hRegular and it didn't appear in the other settings, fine. But when i create another view in wCompact / hAny, the view also appear in the wCompact/hRegular configuration. – Zé Moreira Dec 27 '15 at 16:47
  • It should, that's how size classes are made. Maybe you could do this with some code? – stek29 Dec 27 '15 at 16:51
  • Did you have any tutorial to indicate? I'm really lost in this subject =/ – Zé Moreira Dec 27 '15 at 16:51
  • @ZéMoreira Read [this](http://stackoverflow.com/questions/26028918/ios-how-to-determine-iphone-model-in-swift) [this](http://stackoverflow.com/questions/27039140/programmatically-set-image-to-uiimageview-with-xcode-6-1-swift) [this](http://stackoverflow.com/questions/25666269/ios8-swift-how-to-detect-orientation-change) [this](http://stackoverflow.com/questions/25796545/getting-device-orientation-in-swift). At first you should get device model, then you should get device orientation. But if device orientation can be changed you need listener for this.And all these should change image for view. – stek29 Dec 27 '15 at 17:19
  • Thanks, @stek29. So the only way to do that is through code? I thing that it can be done through the storyboard and asset catalog too. – Zé Moreira Dec 27 '15 at 18:41
  • Only Size Classes then, but you've said that it's not suitable for you. – stek29 Dec 27 '15 at 18:46
  • it's suitable, i just don't know how is the best way to do it =/ – Zé Moreira Dec 27 '15 at 19:22
0

You can add a new image to your Asset catalogue: Activate iPhone and iPad and choose the size classes you need:

enter image description here

Stefan
  • 5,203
  • 8
  • 27
  • 51