lorenzo
lorenzo

Reputation: 1743

How to define an asset for iPad in landscape

I'm adapting for the first time an iPhone app to iPad. I was glad to see that assets are really powerful when I made the iPad's portrait version. Now I'm working on the landscape version and I realized that some of my images need to be specifically made for landscape.

I'm not sure how to do this. Launch images have landscape variations, but image sets haven't.

How can add a landscape variation in my image set?

Best regards.

Upvotes: 0

Views: 475

Answers (2)

Dan Atherton
Dan Atherton

Reputation: 161

I'm not sure if there is a setting in xcassets that will allow you to do this, but here are some strategies:

9 Slice your images

UIImage *initialImage = [UIImage imageNamed:@"someImage"];
UIImage *nineSlicedImage = [initialImage  resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
[self.myImageView setImage:nineSlicedImage]

Set correct image at Runtime

You can use

[[UIDevice currentDevice] orientation]

to check your current orientation

Set ImageView mode correctly In the .xib or .storyboard you can set the mode of a image view to be center/left/right/aspect fit/ aspect fill etc

enter image description here

remember to set the image view to clip subviews or the image can show regardless of the frame

Upvotes: 1

dOM
dOM

Reputation: 555

you can create a iPad-only xib

i.e, MainView.xib would become MainView~ipad.xib

Upvotes: 0

Related Questions