標籤: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];
運行效果: