对于剪切矩形图像:
UIImage *croppedImg = nil;
CGRect cropRect = CGRectMake(100 , 100, 50, 50);// set as you need
croppedImg = [self croppIngimageByImageName:self.imageView.image toRect:cropRect];
使用以下返回方法UIImage
(如您想要的图像大小)
- (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect
{
//CGRect CropRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15);
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
Here You get cropped
image and you can put it on you like (also put image on newView
and add it io you )backGroungColor
UIImageView
newView
UIView *newView = [[UIView alloc]initWithFrame:CGRectMake("as YOu Need")];
self.tblView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:cropped]];
[self.view addSubView:newView];