Uiimageview view can display pictures
There are two methods of instantiating Uiimageview
The first method: Uiimageview *myimageview = [[Uiimageview alloc] Initwithimage: [UIImage imagenamed: @ "demo"]];
Use this method to display the original size of the picture.
Second method: Uiimageview *myimageview = [[UIImage alloc] initWithFrame:self.view.bounds]
This method displays the picture at a specified size, regardless of the original size of the picture, causing the picture to deform.
In many cases, you need to place the picture in a range of a specified size and not distort the picture. Resolve the issue to set the Contentmode property of the Uiimageview. Contentmode is an enumeration:
typedef NS_ENUM(NSInteger, UIViewContentMode){ UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight};
The three most commonly used modes are:
Uiviewcontentmodescalefill: The picture will be filled in the picture view;
Uiviewcontentmodescaleaspectfit: Will make the picture with the original aspect ratio to adapt to the picture view;
Uiviewcontentmodescaleaspectfill: First to set the Clipstobounds property of the picture view to Yes, so that the image fills the entire picture view with its original aspect ratio, and the excess part will be clipped out;
So the general Set Picture view mode is Uiviewcontentmodescaleaspectfit.
iOS uiimageview handling picture size issues