iOS SDK UIViewContentModeScaleAspectFit 与 UIViewContentModeScaleAspectFill

发布于 2024-09-08 06:43:36 字数 781 浏览 13 评论 0原文

我有一个图像,我想使用提供 UIImageViewUITableViewCellStyleSubtitle 样式在 UITableViewCell 中显示,以及两行文本,加上可选附件视图。

但是,当我将 UIImageView 的内容模式设置为 UIViewContentModeScaleAspectFitUIViewContentModeScaleAspectFill 时,它似乎没有什么区别。这两种内容模式都只是显示整个图像,将文本向右移动以为图像腾出空间。

有谁有任何例子来说明这些在实践中有何不同?文档说:

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.

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.

但这些内容模式的表现似乎并不像广告中所宣传的那样。

编辑:我正在运行 SDK iOS 4。

I have an image that I would like to display in a UITableViewCell using the UITableViewCellStyleSubtitle style that provides a UIImageView, and two lines of text, plus an optional accessory view.

However, when I set the content mode of the UIImageView to either of UIViewContentModeScaleAspectFit or UIViewContentModeScaleAspectFill, it appears to make no difference. Both of these content modes simply display the entire image, shifting the text to the right to make room for the image.

Does anyone have any examples of how these actually differ in practice? The docs say:

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.

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.

But these content modes don't appear to be behaving as advertised.

EDIT: I'm running SDK iOS 4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再见回来 2024-09-15 06:43:36

我也有同样的问题。
看来苹果的文档有点缺乏。

我通过在互联网上搜索找到了答案。
http://www.iphonedevsdk.com/forum/ iphone-sdk-development/2973-crop-image.html

基本上,

img1.contentMode = UIViewContentModeScaleAspectFill; 
img1.clipsToBounds = YES;

如果你想让它更奇特一点,请查看这篇文章:
UIImageView 更改宽度和高度

I had the same problem.
Seems like the Apple documentation is a bit lacking.

I found the answer by searching around the internet.
http://www.iphonedevsdk.com/forum/iphone-sdk-development/2973-crop-image.html

Basically,

img1.contentMode = UIViewContentModeScaleAspectFill; 
img1.clipsToBounds = YES;

If you want it to be a bit more fancy, check out this post:
UIImageView change Width and Height

一人独醉 2024-09-15 06:43:36

您看不到这些模式之间的差异的原因是 UITableViewCell 自动调整其图像视图的大小以适应图像的宽高比。仅当视图的宽高比与图像的宽高比不同时,内容模式才会发挥作用。

要么重写自定义 UITableViewCell 类中的 layoutSubviews,要么自己创建一个图像视图(不要使用表视图单元格提供的视图)。

The reason you don't see a difference between those modes is that the UITableViewCell automatically sizes its image view to fit the aspect ratio of the image. The content modes only come into play when the view's aspect ratio is different from the image's.

Either override layoutSubviews in your custom UITableViewCell class or create an image view yourself (don't use the one that the table view cell provides).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文