Auto Layout is supposed to help in this situation.
Now tell me @Nicklas Berglund, what would you do if the device rotates? Suppose now you are in landscape mode. How would you fill a horizontal space that is no longer in the images?
Just food for thought. An auto market that should take care of your screen, no matter what orientation or device you use for your application.
Perhaps Apple should start targeting devices in the future?
Let's get back to your question .. The solution is to replace your @ 2x images with 750 pixel wide images and then auto-layout. Oh yes, that is the hard part.
If you just add constraints to fit them, it will compress it horizontally when displayed on a 4-inch screen, but you can use multipliers to scale the image accordingly. Here's how you can do it:
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageFooterView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(imageFooterView)]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageFooterView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(imageFooterView)]]; float aspectRatio = imageFooterView.frame.size.height/imageFooterView.frame.size.width; [imageFooterView addConstraint:[NSLayoutConstraint constraintWithItem:imageFooterView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:imageFooterView attribute:NSLayoutAttributeWidth multiplier:aspectRatio constant:0.0f]];
Bms270 Oct 15 '14 at 14:51 2014-10-15 14:51
source share