(网络图片,侵删)
创建UIImage分类中的方法
- (UIImage *)dc_stretchLeftAndRightWithContainerSize:(CGSize)imageViewSize
{
CGSize imageSize = self.size;
CGSize bgSize = CGSizeMake(floorf(imageViewSize.width), floorf(imageViewSize.height)); //imageView的宽高取整,否则会出现横竖两条缝
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;
}
网友评论