Crop image
<pre>
-(UIImage *)cropImage:(CGRect)bounds{
** //crop image with bounds **
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds);
** //get a UIImage **
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
** //**
CGImageRelease(imageRef);
** //**
return croppedImage;
}
</pre>
Strech Image
在進(jìn)行圖片拉伸的時(shí)候可能并不是每個(gè)部分你都想拉伸,這時(shí)候你可以使用下面的辦法來解決
-(UIImage*)resizableImageWithCapInsets(UIEdgeInsets)capInsetsresizingMode:(UIImageResizingMode)resizingMode
CapInsets:拉升的范圍,上,左,下,右。eg.UIEdgeInsetsMake(15, 15, 15, 15),拉升距離上邊15,左邊,15,下邊15,右邊15.
resizingMode:選擇UIImageResizingModeStretch,拉伸模式
下面看看具體效果


后面的尖角部分沒有拉伸
-(UIImage*)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidthtopCapHeight:(NSInteger)topCapHeight
此方法和上面的相似,指定(x,y)。距離左邊,和上邊的距離,得到一個(gè)點(diǎn),拉伸這個(gè)點(diǎn)去填充被拉伸出來的部份
此外在xcode的Images.xcassets中也可以設(shè)置,點(diǎn)圖片,右下方的show slicing