在iphone6+上使用@2x~ipad;
我有一个应用程序,它使用巨大的图像来安装iPad@2x~iPad。我想在我的通用应用程序的iPhone版本中使用相同的图像。有没有办法在iPhone 6+@3x上使用相同的图像在iphone6+上使用@2x~ipad;,ipad,iphone-6-plus,Ipad,Iphone 6 Plus,我有一个应用程序,它使用巨大的图像来安装iPad@2x~iPad。我想在我的通用应用程序的iPhone版本中使用相同的图像。有没有办法在iPhone 6+@3x上使用相同的图像 我不想两者都有一个非常相似的图像,应用程序将在MB部门变得很大 唯一的方法是不要使用自动命名标准,而是编写代码,根据设备决定使用哪个图像名称 假设您正在按钮中使用大图像。您当前使用的代码可能与此类似 [buttonView setImage:[UIImage ImageName:largeImage]用于状态:UICon
我不想两者都有一个非常相似的图像,应用程序将在MB部门变得很大 唯一的方法是不要使用自动命名标准,而是编写代码,根据设备决定使用哪个图像名称 假设您正在按钮中使用大图像。您当前使用的代码可能与此类似 [buttonView setImage:[UIImage ImageName:largeImage]用于状态:UIControlStateNormal] 改为这样做
NSString *pictFile = [[NSBundle mainBundle] pathForResource:@"largeImage" ofType:@"png"];
UIImage *imageToDisplay = [UIImage imageWithContentsOfFile:pictFile];
UIImage *checkboxImage = [UIImage imageWithCGImage:imageToDisplay.CGImage scale: [UIScreen mainScreen].scale orientation:imageToDisplay.imageOrientation];
[buttonView setImage:checkboxImage forState:UIControlStateNormal];
我有很多大图像,当视网膜显示出来的时候我就开始这样做了。它同样适用于新手机。如果帧对于图像来说太大,则可能会遇到问题。e、 g.@3x帧大小为100x100,但您的图像仅为90x90。如果出现这种情况,请强制将图像比例设置为2x。你将无法看到照片的不同之处。我可以在iPhone6Plus上看到我的大图有所不同,所以我将比例因子保留为2
我正在处理掉我所有的@1x和@2x图像,只使用没有@的@3x图像。在按钮和背景的模拟器中工作。这里是使用一个非常大的图像而不是三个图像的另一个示例。这次我在整个视图中放置了一个大背景图像,而不是一个按钮。这段代码的关键部分是self.BGView.contentMode=UIViewContentModeScaleAspectFit;这将调整图像的大小,使其适合视图
- (void)pickBackgroundImage {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat scale = [UIScreen mainScreen].scale;
CGPoint midPoint = [Utilities findMidpoint:self.view];
NSString *pictFile = [[NSBundle mainBundle] pathForResource:@"Background" ofType:@"png"];
UIImage *imageToDisplay = [UIImage imageWithContentsOfFile:pictFile];
imageToDisplay = [UIImage imageWithCGImage:imageToDisplay.CGImage scale:scale orientation:imageToDisplay.imageOrientation];
CGRect pictFrame;
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
CGFloat imageWidth = (unsigned int)(.9f * self.view.frame.size.width);
pictFrame = CGRectMake(midPoint.x - imageWidth/2, midPoint.y - imageWidth/2, imageWidth, imageWidth);
pictFrame.origin.y = self.view.frame.origin.y + .3f * pictFrame.origin.y;
} else {
CGFloat imageWidth = (unsigned int)(self.view.frame.size.height - 20 - 44);
pictFrame = CGRectMake(midPoint.x - imageWidth/2, midPoint.y - imageWidth/2, imageWidth, imageWidth);
pictFrame.origin.y = 10;
}
self.BGView = [[UIImageView alloc] initWithImage:imageToDisplay];
self.BGView.frame = pictFrame;
self.BGView.contentMode = UIViewContentModeScaleAspectFit;
[self.view insertSubview:self.BGView atIndex:0];
}