![](/img/trans.png)
[英]Dynamically use UIViewContentModeScaleAspectFit and UIViewContentModeScaleAspectFill
[英]iOS SDK UIViewContentModeScaleAspectFit vs. UIViewContentModeScaleAspectFill
我有一個圖像,我想在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.
但是這些內容模式似乎沒有像宣傳的那樣表現。
編輯:我正在運行SDK iOS 4。
我有同樣的問題。 似乎Apple文檔有點缺乏。
我在網上搜索找到了答案。 http://www.iphonedevsdk.com/forum/iphone-sdk-development/2973-crop-image.html
基本上,
img1.contentMode = UIViewContentModeScaleAspectFill;
img1.clipsToBounds = YES;
如果你想要它更有趣,請看看這篇文章: UIImageView改變寬度和高度
您沒有看到這些模式之間的差異的原因是UITableViewCell
自動調整其圖像視圖的大小以適合圖像的寬高比。 僅當視圖的寬高比與圖像不同時,內容模式才會發揮作用。
要么在自定義UITableViewCell
類中覆蓋layoutSubviews
,要么自己創建一個圖像視圖(不要使用表視圖單元提供的那個)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.