標籤:ios6 技術分享 影響 使用 int http ios圖片 pca 高度
http://blog.csdn.net/q199109106q/article/details/8615661
- - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
- // width為圖片寬度
- rightCapWidth = width - leftCapWidth - 1;
-
- // height為圖片高度
- bottomCapHeight = height - topCapHeight - 1
經過計算,你會發現中間的可展開地區只有1x1
[java] view plain copy
- // stretchWidth為中間可展開地區的寬度
- stretchWidth = width - leftCapWidth - rightCapWidth = 1;
-
- // stretchHeight為中間可展開地區的高度
- stretchHeight = height - topCapHeight - bottomCapHeight = 1;
因此,使用這個方法只會展開圖片中間1x1的地區,並不會影響到邊緣和角落。
下面示範下方法的使用:
[java] view plain copy
- // 左端蓋寬度
- NSInteger leftCapWidth = image.size.width * 0.5f;
- // 頂端蓋高度
- NSInteger topCapHeight = image.size.height * 0.5f;
- // 重新賦值
- image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
- - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
- CGFloat top = 25; // 頂端蓋高度
- CGFloat bottom = 25 ; // 底端蓋高度
- CGFloat left = 10; // 左端蓋寬度
- CGFloat right = 10; // 右端蓋寬度
- UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
- // 伸縮後重新賦值
- image = [image resizableImageWithCapInsets:insets];
三、iOS 6.0
在iOS6.0中,UIImage又提供了一個方法處理圖片展開
[java] view plain copy
- - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
對比iOS5.0中的方法,只多了一個UIImageResizingMode參數,用來指定展開的模式:
- UIImageResizingModeStretch:展開模式,通過展開UIEdgeInsets指定的矩形地區來填充圖片
- UIImageResizingModeTile:平鋪模式,通過重複顯示UIEdgeInsets指定的矩形地區來填充圖片
可以拿到圖片直接在xcode右側設定,會自動計算保護地區
ios圖片的展開