iOS SDK UIViewContentModeScaleAspectFit与UIViewContentModeScaleAspectFill

Dal*_*zio 16 iphone objective-c uiimageview contentmode ios4

我有一个图像,我希望UITableViewCell使用UITableViewCellStyleSubtitle提供一个UIImageView和两行文本的样式,以及一个可选的附件视图显示.

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

有没有人在实践中有任何实际差异的例子?文档说:

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.
Run Code Online (Sandbox Code Playgroud)

但是这些内容模式似乎没有像宣传的那样表现.

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

Jon*_*Jon 35

我有同样的问题.似乎Apple文档有点缺乏.

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

基本上,

img1.contentMode = UIViewContentModeScaleAspectFill; 
img1.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

如果你想要它更有趣,请看看这篇文章: UIImageView改变宽度和高度

  • 三个小时之后,`clipsToBounds`正是我所寻找的.谢谢. (3认同)

omz*_*omz 9

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

layoutSubviews在自定义UITableViewCell类中覆盖或自己创建图像视图(不要使用表视图单元提供的视图).