我看过关于图像大小的各种旧帖子,但是我找不到任何最新的信息,甚至不知道是否可以用资产目录为所有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