佚名通过本文主要向大家介绍了taylorswiftstyle,taylorswift13,音悦台taylorswift,霉霉taylorswift,taylorswiftwildest等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:taylor swift图片 swift如何只显示图片的一部分。
描述:
解决方案1:
描述:
UI图都放在一张图片上了,请问我在给UIbutton设置背景图片的时候如何只显示UI图片的特定位置、大小的一部分,用来给button做背景。
解决方案1:
参考stackoverflow:http://stackoverflow.com/a/8443937
rect就是你要的部分的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;
}