WX20170403-114055.png
(網(wǎng)絡(luò)圖片哆档,侵刪)
創(chuàng)建UIImage分類中的方法
- (UIImage *)dc_stretchLeftAndRightWithContainerSize:(CGSize)imageViewSize
{
CGSize imageSize = self.size;
CGSize bgSize = CGSizeMake(floorf(imageViewSize.width), floorf(imageViewSize.height)); //imageView的寬高取整芹壕,否則會(huì)出現(xiàn)橫豎兩條縫
UIImage *image = [self stretchableImageWithLeftCapWidth:imageSize.width *0.8 topCapHeight:imageSize.height * 0.5];
CGFloat tempWidth = (bgSize.width)/2 + (imageSize.width)/2;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(tempWidth, bgSize.height), NO, [UIScreen mainScreen].scale);
[image drawInRect:CGRectMake(0, 0, tempWidth, bgSize.height)];
UIImage *firstStrechImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *secondStrechImage = [firstStrechImage stretchableImageWithLeftCapWidth:imageSize.width *0.2 topCapHeight:imageSize.height*0.5];
return secondStrechImage;
}