轉載至CSDN http://blog.csdn.net/yi_zz32/article/details/50381762
我們在開發中,經常要在view,tableView,等顯示圖片,比如我們發微博(帶有圖片的),那么我們常常要考慮如何處理這些圖片,是否拉伸,拉伸到什么樣的效果等等,常常是需要考慮的問題
其實主要的還是要理解UIImageView的ContentMode的這些參數,這些參數一般就能滿分我們的開發需求
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,
那我們接下來,就來說明一下,這些值都代表什么意思
UIViewContentModeScaleToFill:圖片拉伸至填充這個UIImageView(圖片可能變形)
UIViewContentModeScaleAspectFit : 圖片拉伸至完全顯示在UIImageView里面為止(圖片不會變形)
UIViewContentModeScaleAspectFill : 圖片拉伸至 圖片的寬度等于UIImageView的寬度 或者 圖片的高度等于UIImageView的高度為止,然后將圖片居中顯示
UIViewContentModeRedraw : 調用了setNeedsDisplay方法時,就會將圖片重新渲染
UIViewContentModeCenter:居中顯示