我看過關於圖像大小的各種舊帖子,但是我找不到任何最新的信息,甚至不知道是否可以用資產目錄爲所有iPad和iPhone屏幕尺寸提供圖像。Xcode 7,資產目錄通用設備背景圖像支持?
這是我找到的最好的職位,但在Xcode 7它不顯示 「視網膜4 2X」 或iPhone 6/6+
Xcode 6 - xcassets for universal image support
在Xcode 7有一個通用選項,但三個圖像不支持所有設備尺寸。
我見過可以在資產目錄之外提供自己的圖像的選項,但我真的很喜歡使用資產目錄。
How to use xcassets/universal background images for different iPhones/iPads?
編輯: 它看起來像我可能會去的無資產目錄路徑:(
A)
我想將來證明這一解決方案,所以它退後,如果需要,調整最適合的圖像,因爲我不知道會發生。
NSNumber *screenWidth = @([UIScreen mainScreen].bounds.size.width);
NSString *imageName = [NSString stringWithFormat:@"name-%@w", screenWidth];
UIImage *image = [UIImage imageNamed:imageName];
B)
或者,也許這段代碼是更好?雖然我不確定這是什麼尺寸,但它也有點過時,因爲它不支持x3圖像?
#import <UIKit/UIKit.h>
@interface UIImage (DefaultImage)
// uses statusbar orientation
+ (UIImage *)defaultImage;
//uses given orientation
+ (UIImage *)defaultImageForOrientation:(UIInterfaceOrientation)orient;
@end
@implementation UIImage (DefaultImage)
+ (UIImage *)defaultImage {
return [self defaultImageForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}
+ (UIImage *)defaultImageForOrientation:(UIInterfaceOrientation)orient {
// choose the correct launch image for orientation, device and scale
NSMutableString *launchImageName = [[NSMutableString alloc] initWithString:@"Default"];
BOOL isPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
if (isPad) {
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orient);
NSString *imageOrientation = (isLandscape) ? @"Landscape" : @"Portrait";
BOOL isRetina = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0);
NSString *scaleString = (isRetina) ? @"@2x" : @"";
// Default-Landscape~ipad.png
// [email protected]~ipad.png
// Default-Portrait~ipad.png
// [email protected]~ipad.png
launchImageName = [NSMutableString stringWithFormat:@"%@-%@%@.png", launchImageName, imageOrientation, scaleString];
} else {
if (CGRectGetHeight([UIScreen mainScreen].bounds) > 480.f) {
// Default-568h.png
launchImageName = [NSMutableString stringWithFormat:@"%@-568h.png", launchImageName];
} else {
// Default.png
// [email protected]
launchImageName = [NSMutableString stringWithFormat:@"%@.png", launchImageName];
}
}
return [UIImage imageNamed:launchImageName];
}
@end
免責聲明:從https://github.com/Daij-Djan/DDUtils
C線)
這看起來也不錯,但它的調整大小,而不是使用實際的清晰的圖像,而且也沒有回落。
https://gist.github.com/kevindelord/fe2e691d06ab745fbb00
NSString *extension = @""; // iPhone 3GS and earlier
if (scale == 3.f) {
extension = @"@3x"; // iPhone 6 Plus
} else if (scale == 2.f && h == 568.0f && w == 320.0f) {
extension = @"[email protected]"; // iPhone 5, 5S, 5C
} else if (scale == 2.f && h == 667.0f && w == 375.0f) {
extension = @"[email protected]"; // iPhone 6
} else if (scale == 2.f && h == 480.0f && w == 320.0f) {
extension = @"@2x"; // iPhone 4, 4S
} else if (scale == 1.f && h == 1024.0f && w == 768.0f) {
extension = @"-512h"; // iPad Mini, iPad 2, iPad 1
} else if (scale == 2.f && h == 1024.0f && w == 768.0f) {
extension = @"[email protected]"; // iPad Mini 3, iPad Mini 2, iPad Air, iPad Air 2
}
return extension;
我問同樣的問題************,似乎沒有人關心。這就像是,超級重要爲什麼沒有人回答? (順便說一句,你最終做了什麼與iPad的圖像..?) – durazno
我已經結束了使用畫圖代碼來繪製我的背景的事實我幾乎取代了我的所有圖像。在我的情況下,我需要調整事物的大小,因此再生圖像是不切實際的。 – Jules
所以你已經決定一點點地丟失圖像的質量,並儘量減少二進制文件的大小..?我正在尋找的是兩者的解決方案。我不想失去質量沒有一點,同時也不想獲得二進制大小... – durazno