Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - making the picture fit on the screen

Tags:

ios

iphone

ipad

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.

like image 873
John Appleseed Avatar asked Nov 10 '11 11:11

John Appleseed


People also ask

How do I Crop my iPhone wallpaper?

Unlock your ‌‌‌iPhone‌‌‌ with Face ID or Touch ID. Press and hold on the Lock Screen to enter the wallpaper gallery. Swipe if necessary to the Lock Screen wallpaper that you want to crop, then tap Customize. Perform a pinch gesture on the wallpaper to crop the image and get the desired effect.

How do I get a picture to fit my phone background?

Tip: touch and hold the empty space on your home screen and select Wallpaper at the bottom to reach the wallpaper setting screen. Pick the image you want to use as your background. Once your image (portrait or landscape) is selected, you will see a preview of your wallpaper filling up your whole screen.


2 Answers

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;
like image 113
Nekto Avatar answered Oct 01 '22 13:10

Nekto


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

like image 45
Gloomcore Avatar answered Oct 01 '22 12:10

Gloomcore