Reputation: 4061
I have a single view with two custom layouts, one for Landscape and one for Portrait. These view objects also (currently) have two images, one for each view.
Example: one image has a text component. To avoid stretching the image, we've made one for portrait and one for landscape.
What I'm trying to avoid is is a bunch of if statements that determine which orientation is being shown and thus which image to use. Is there a way to avoid all this extra code?
Upvotes: 0
Views: 124
Reputation: 4029
Sort of...using image names set accordingly. I mean you can name them image_portrait.png and image_landscape.png and then in your willRotateToInterfaceOrientation..
method do something like this:
NSString *orientation = (UIInterfaceOrientationIsPortrait(orientation)) ? @"portrait" : @"landscape";
[imgView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image_%@",orientation]]];
I don't know of anything you can do more than this. Sure , this doesn't look like much of an improvement but if you have more images it will be quite useful.
Hope this helps.
Cheers!
Upvotes: 2