尝试在 UIImageView 中设置大图像时,图像的分辨率会失真。有没有办法在将图像放入较小的视图时保持相同的分辨率?
问问题
2482 次
4 回答
5
尝试将 imageview 内容模式设置为 aspectfit。
imageView.contentMode = UIViewContentModeScaleAspectFit;
于 2012-05-18T13:21:24.047 回答
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.
于 2012-05-18T14:44:08.797 回答
2
设置大小必须在设置 contentMode 之后发生
[imageView setContentMode: UIViewContentModeScaleAspectFit];
imageView.frame = CGRectMake(x, y, width, height);
于 2013-09-16T19:09:22.510 回答
1
我通过将图像大小调整为包含图像的 UIImageView 的大小来解决此问题。
对我来说,imageView.contentMode = UIViewContentModeScaleAspectFit
设置 imageView 的框架也不起作用。
场景:
我正在使用 Xib 的 UITableViewCell,它有一个 UIImageView。我以编程方式为 UIImageView 设置图像。
于 2014-01-03T04:19:24.437 回答