参考stackoverflow:http://stackoverflow.com/a/8443937rect就是你要的部分的x/y/width/height,改写成swift的写法就可以了 - (UIImage *)crop:(CGRect)rect { if (self.scale > 1.0f) { rect = CGRectMake(rect.origin.x * self.scale, rect.origin.y * self.scale, rect.size.width * self.scale, rect.size.height * self.scale); } CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect); UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation]; CGImageRelease(imageRef); return result; }
参考stackoverflow:http://stackoverflow.com/a/8443937
rect就是你要的部分的x/y/width/height,改写成swift的写法就可以了