ios圖片展開方法(5.0-6.0)

來源:互聯網
上載者:User

標籤:des   style   blog   http   os   io   strong   ar   

一、iOS 5.0

在iOS 5.0中,UIImage又有一個新方法可以處理圖片的展開問題

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets

這個方法只接收一個UIEdgeInsets類型的參數,可以通過設定UIEdgeInsets的left、right、top、bottom來分別指定左端蓋寬度、右端蓋寬度、頂端蓋高度、底端蓋高度

1 CGFloat top = 25; // 頂端蓋高度2 CGFloat bottom = 25 ; // 底端蓋高度3 CGFloat left = 10; // 左端蓋寬度4 CGFloat right = 10; // 右端蓋寬度5 UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);6 // 伸縮後重新賦值7 image = [image resizableImageWithCapInsets:insets];

運行效果:

 

二、iOS 6.0

在iOS6.0中,UIImage又提供了一個方法處理圖片展開

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode

對比iOS5.0中的方法,只多了一個UIImageResizingMode參數,用來指定展開的模式:

  • UIImageResizingModeStretch:展開模式,通過展開UIEdgeInsets指定的矩形地區來填充圖片
  • UIImageResizingModeTile:平鋪模式,通過重複顯示UIEdgeInsets指定的矩形地區來填充圖片
1 CGFloat top = 25; // 頂端蓋高度2 CGFloat bottom = 25 ; // 底端蓋高度3 CGFloat left = 10; // 左端蓋寬度4 CGFloat right = 10; // 右端蓋寬度5 UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);6 // 指定為展開模式,伸縮後重新賦值7 image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];

運行效果:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.