簡體   English   中英

圖片無法按比例顯示在圖片視圖中

[英]Image won't fit in scale to fill mode in image view

這是一個非常簡單的任務,但是對我來說不起作用。 這是我所做的:

  1. 在情節提要中,將圖像視圖添加到我的控制器中,將每一側固定到Superview,且距離為0。
  2. 將圖像視圖的圖像設置為646 x 1140的PNG圖像。
  3. 設置模式以縮放以填充

然后在我的模擬器中,視圖控制器如下所示:

錯誤的屏幕截圖

如屏幕截圖所示,圖像周圍有空白。

我可以確認圖像本身周圍沒有空格,並且圖像視圖很好地固定在其視圖的四個側面。 那么為什么會這樣呢? 我有想念嗎?

可能是您的圖像從左到右一點透明,如果白色也會改變,則嘗試更改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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM