[英]Image won't fit in scale to fill mode in image view
這是一個非常簡單的任務,但是對我來說不起作用。 這是我所做的:
然后在我的模擬器中,視圖控制器如下所示:
如屏幕截圖所示,圖像周圍有空白。
我可以確認圖像本身周圍沒有空格,並且圖像視圖很好地固定在其視圖的四個側面。 那么為什么會這樣呢? 我有想念嗎?
可能是您的圖像從左到右一點透明,如果白色也會改變,則嘗試更改veiw的顏色,然后它將確認。
將您的圖像設置為
yourimage.contentMode = UIViewContentModeScaleAspectFit;
根據apple documentation
使用的其他一些變體
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.