Question: Why Imageview always streched show image streched iOS?

Question

Why Imageview always streched show image streched iOS?

Answers 2
Added at 2017-01-03 10:01
Tags
Question

I have use the imageview and it contains different images but some image show stretched then how to Show image without stretched.I use below code for the Image, I set the property aspect fit but due to that ImageView take size of images not the Imageview and display as different size. I want to display image with one size and without stretched.

   imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 190, 190)];
   imageview1.contentMode = UIViewContentModeScaleAspectFit;
   imageview1.clipsToBounds = YES;

Appreciate for Help Thanks!!!

Answers
nr: #1 dodano: 2017-01-03 11:01

Please try setting content mode before setting frame like below

 imageview1.contentMode = UIViewContentModeScaleAspectFit;
 imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 190, 190)];      
 imageview1.clipsToBounds = YES;
nr: #2 dodano: 2017-01-03 15:01

If you want to display each image without stretching and of same size, than set contentMode property of UIImageView's instance to UIViewContentModeScaleAspectFill. For instance-

imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 190, 190)];
imageview1.contentMode = UIViewContentModeScaleAspectFill;
imageview1.clipsToBounds = YES;

UIViewContentModeScaleAspectFill, will fill the entire area of image view, keeping the aspect ratio intact. In the process of filling entire image view, either vertical or horizontal length will be fully covered and the filling will continue till the time other dimension is fully filled. In the process, your content(either across vertical or horizontal) will be visible outside the frame. To clip this extra content we have set clipsToBounds property of image view to YES.

UIViewContentModeScaleAspectFit, will fill the image view's area till the time any one length either vertical or horizontal is fully filled keeping the aspect ratio intact. Its useful, if you are not required to show each image as same size as the other direction (if vertical is fully filled than horizontal or vice versa), is not fully covered. Since this will show blank spaces in the direction which is not fully covered.

Source Show
◀ Wstecz