The main image of this article introduces the Contentmode properties of UIView:
Core code
[Self.prp_imageview Setcontentmode:uiviewcontentmodescaleaspectfill];
Self.prp_imageView.clipsToBounds = YES;
Uiviewcontentmodescaleaspectfit,//This image will be displayed in the view, and the proportion is not changed this means that if the picture and view are not the same proportion, there will be white like 1
Uiviewcontentmodescaleaspectfill,//This is the entire view will be filled with the picture, the picture scale is not changed, so that the picture will be larger than the view such as 2
Since the request is not high and can not be left white then I could use the second but this is out of position, so the colleague again asked to cut off on it.
And then the whole process is two steps.
[Self.prp_imageview Setcontentmode:uiviewcontentmodescaleaspectfill];
Self.prp_imageView.clipsToBounds = YES;
The perfect solution to the following is
I really like them so much, just be my model for the time being.
And then I put it all on the test again, all the different people look at the picture summary
Uiviewcontentmodecenter
Uiviewcontentmodetop
Uiviewcontentmodebottom
Uiviewcontentmodeleft
Uiviewcontentmoderight
Uiviewcontentmodetopleft
Uiviewcontentmodetopright
Uiviewcontentmodebottomleft
Uiviewcontentmodebottomright
Other more detailed properties are described in:
UIView has a Uiviewcontentmode type of property Contentmode, which you can use to modify the view's content display mode.
View Sourceprint?
01.typedef NS_ENUM(NSInteger, UIViewContentMode) {
02.UIViewContentModeScaleToFill,
03.UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent 04.UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped. 05.UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
06.UIViewContentModeCenter, // contents remain same size. positioned adjusted.
07.UIViewContentModeTop,
08.UIViewContentModeBottom,
09.UIViewContentModeLeft,
10.UIViewContentModeRight,
11.UIViewContentModeTopLeft,
12.UIViewContentModeTopRight,
13.UIViewContentModeBottomLeft,
14.UIViewContentModeBottomRight,
15.};
Instance code:
View Sourceprint?
1.CGRect rect = self.view.frame;
2.UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
3.imageView.contentMode = UIViewContentModeTop;
4.imageView.image = [UIImage imageNamed:@demoImage];
5.[self.view addSubview:imageView];
Uiviewcontentmodescaletofill
Stretches the contents of the picture according to the scale of the view.
Uiviewcontentmodescaleaspectfit
Maintain the aspect ratio of the picture content to fit the view size.
Uiviewcontentmodescaleaspectfill
Fills the size of the view with the contents of the picture, and the extra parts can be trimmed off to fill the entire view boundary.
Uiviewcontentmoderedraw
This option is displayed again by calling the Setneedsdisplay method when the size position of a single view changes.
Uiviewcontentmodecenter
Keep picture proportions in the middle of the view display picture content
If the view size is smaller than the size of the picture, the picture goes beyond the view boundary, similar to
Uiviewcontentmodetop
Keep the picture in its original proportions display the picture content at the top of the view
Uiviewcontentmodebottom
Keep picture content in the middle of the view at the bottom of the picture
Uiviewcontentmodeleft
Keep picture proportions in the middle of the view Show picture content on the left
Uiviewcontentmoderight
Keep the picture in proportion to the right of the middle of the view display picture content
Uiviewcontentmodetopleft
Keep picture proportions in the upper left corner of the view display picture content
Uiviewcontentmodetopright
Keep picture proportions in the upper right corner of the view display picture content
Uiviewcontentmodebottomleft
Keep picture proportions in the lower left corner of the view display picture content
Uiviewcontentmodebottomright
Keep picture proportions in the lower right corner of the view display picture content
"Original from: Http://www.2cto.com/kf/201507/412894.html"
iOS picture fill Uiimageview (Contentmode)