Reputation: 53
I am new to iPhone development. I am creating an app where I take a picture and I must present it on the screen full screen. But I am having difficulties understanding some stuff.
For example: imagine the user selects a picture that has a different aspect ratio compared with iPad's screen. As I am presenting the picture full screen, I don't want to display any black bars left/right or top/bottom and I would like not to distort the picture. How do I calculate the size to display the picture. I mean, how do I calculate the picture size, based on the screen size and orientation so the picture is displayed on the screen without borders, even if the picture has to bleed.
Sorry for asking such a noob question.
Can you point me the direction? Please point me to some code, as my brain is swimming in theory and a code will help me understand that. Thanks.
Upvotes: 5
Views: 7998
Reputation: 950
Just put your picture in the UIImageView and set to it correct contentMode
imageView.contentMode = UIViewContentModeScaleAspectFill;
UIViewContentModeScaleAspectFill - will fill whole screen by your image, but the image will not be distorted by screen proportions
Upvotes: 2
Reputation: 17877
You can use UIImageView
to display image (UIImage
).
You can manage the behavior of displayed image (cropped, scaled to fit, centered) by changing property contentMode
of UIImageView
instance:
Specifies how a view adjusts its content when its size changes.
typedef enum {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
} UIViewContentMode;
Upvotes: 6