我有一款使用巨大圖像來適應iPad @ 2x〜ipad的應用程序。我想在iPhone版的通用應用程序中使用這些相同的圖像。有沒有一種方法可以將這些圖像用於iPhone 6 + @ 3x?在iPhone 6+上使用@ 2x〜ipad
我不希望兩者都有非常相似的圖像,該應用程序會在MB部門變大。
我有一款使用巨大圖像來適應iPad @ 2x〜ipad的應用程序。我想在iPhone版的通用應用程序中使用這些相同的圖像。有沒有一種方法可以將這些圖像用於iPhone 6 + @ 3x?在iPhone 6+上使用@ 2x〜ipad
我不希望兩者都有非常相似的圖像,該應用程序會在MB部門變大。
唯一的方法是不使用自動命名標準並編寫代碼來根據設備決定使用哪個圖像名稱。
假設您在按鈕中使用大圖像。您目前使用的代碼可能看起來像這樣。
[buttonView setImage:[UIImage imageNamed:largeImage] forState: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];
我有很多大的圖像,我開始做這個時,視網膜顯示出來。它適用於新手機。如果圖像的幀太大,可能會遇到問題。例如@ 3x幀大小爲100x100,但您的圖像只有90x90。如果發生這種情況,請強制圖像比例@ 2x。你無法看到照片的差異。我可以在iPhone 6 Plus上看到我的大圖的差異 - 所以我將比例因子設置爲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];
}
我不明白這個 – 2014-09-29 22:24:24