尝试在UIImageView中设置大图像时,图像的分辨率会发生变形。有没有办法在适当的分辨率下将图像保持在较小的视图中?
答案 0 :(得分:5)
尝试将imageview内容模式设置为aspectfit。
imageView.contentMode = UIViewContentModeScaleAspectFit;
答案 1 :(得分:3)
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.
答案 2 :(得分:2)
设置尺寸必须在设置contentMode
后进行[imageView setContentMode: UIViewContentModeScaleAspectFit];
imageView.frame = CGRectMake(x, y, width, height);
答案 3 :(得分:1)
我通过将图像大小调整为保存图像的UIImageView的大小来修复此问题。
对我而言,imageView.contentMode = UIViewContentModeScaleAspectFit
也没有设置imageView的框架。
<强>方案强>:
我正在使用Xib的UITableViewCell,它有一个UIImageView。我以编程方式为UIImageView设置图像。