[英]Image for Iphone 4 and Iphone 5
我的应用可以有很多background
images
。 这个images
我需要下载,所以我不想单独下载iPhone 4和iPhone 5 。 我使用方法self.view.backgroundcolor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"myImage.jpg"]]
。 我想为iPhone 5下载一张image
,然后剪切顶部和底部边框以便与iPhone 4一起使用。 我怎样才能以最佳方式以编程方式完成。 哦,也许有解决我问题的最佳解决方案?
您可以使用此功能裁剪图像定义您想要的矩形,因为剩下的图像将被移除,因此您需要CoreGraphics.framework
,所以不要忘记添加到您的项目中。
- (UIImage *)imageByCroppingtoRect:(CGRect)rect fromImage:(UIImage *)image
{
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
尝试这个
- (UIImage *)cropImage:(UIImage *)oldImage {
CGSize imageSize = oldImage.size;
UIGraphicsBeginImageContextWithOptions(CGSizeMake( imageSize.width,imageSize.height - 100),NO,0.); // this height you want to change
[oldImage drawAtPoint:CGPointMake( 0, -46) blendMode:kCGBlendModeCopy alpha:1.];// from top to change X is never change
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return croppedImage;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.