问题
Let say I have a large image (400wx700h) pixels. I want this image to be centered on the iphone and take 1/4 of the display area. Doesn't matter if is iphone 4 or iphone 6+, I still want this image to be centered and take only 1/4 of the display area. Also, I want to design this in storyboard and using constraints, with no coding. I know how to center the image, but not sure about the 1/4 portion. Can someone please guide me?
Thanks Borna
回答1:
Create constraints for equal width and height with the super view, and set the multiplier in each constraint to 0.25
回答2:
- Use a UIImageView to contain your UIImage.
- Set the imageView.contentMode to ScaleToFit
- Use the Equals Widths and Equals Heights constraints from the imageView to your viewController's view.
- Use the multiplier (4 with Inverse Multiplier) on the constraints to adjust the size to what you want.
来源:https://stackoverflow.com/questions/30924523/how-to-proportinally-size-the-image-based-on-the-iphone-is-using