Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView image distorts when big image is placed

While trying to set a big image in UIImageView the resolution of the image distorts. Is there any way to keep the image in same resolution while fitting it in a smaller view?

like image 222
Sahil Tyagi Avatar asked Dec 21 '22 21:12

Sahil Tyagi


2 Answers

try setting imageview content mode to aspectfit.

imageView.contentMode = UIViewContentModeScaleAspectFit;
like image 164
Ronak Avatar answered Jan 17 '23 09:01

Ronak


UIViewContentModeScaleToFill
Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeScaleAspectFit
Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeScaleAspectFill
Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeRedraw
Redisplays the view when the bounds change by invoking the setNeedsDisplay method.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeCenter
Centers the content in the view’s bounds, keeping the proportions the same.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeTop
Centers the content aligned at the top in the view’s bounds.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeBottom
Centers the content aligned at the bottom in the view’s bounds.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeLeft
Aligns the content on the left of the view.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeRight
Aligns the content on the right of the view.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeTopLeft
Aligns the content in the top-left corner of the view.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeTopRight
Aligns the content in the top-right corner of the view.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeBottomLeft
Aligns the content in the bottom-left corner of the view.
Available in iOS 2.0 and later.
Declared in UIView.h.

UIViewContentModeBottomRight
Aligns the content in the bottom-right corner of the view.
Available in iOS 2.0 and later.
Declared in UIView.h.
like image 41
Jaybit Avatar answered Jan 17 '23 09:01

Jaybit