我是iOS编程的新手。我想问一下这些关于不同屏幕尺寸的图像尺寸的问题
答案 0 :(得分:2)
是x,2x和3x图像大小是开发所有iOS设备应用程序所必需的,但iPad和iPad的图像大小可能不同。 iPhone设备,取决于您的iPad和iPad的应用程序UI iPhone。
为了更好地了解背景图片,请查看Adaptivity and Layout
与您的查询相关的最佳文章之一 - Adaptive Layout Tutorial in iOS 9: Getting Started
答案 1 :(得分:0)
如果您为@ 1x,@ 2x和@ 3x制作了图像,请将它们命名为:
myImage.png
myImage@2x.png
myImage-568h@2x.png
myImage-667h@2x.png
myImage-736h@3x.png
然后你可以像下面这样打电话:
UIImage *myImage = [self deviceSizedImageWithName:@"myImage.png"];
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenSize [UIScreen mainScreen].bounds.size
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_4 (IS_IPHONE && kScreenHeight == 480.0f)
#define IS_IPHONE_5 (IS_IPHONE && kScreenHeight == 568.0f)
#define IS_IPHONE_6 (IS_IPHONE && kScreenHeight == 667.0f)
#define IS_IPHONE_6P (IS_IPHONE && kScreenHeight == 736.0f)
- (UIImage *)deviceSizedImageWithName:(NSString *)imageNamed
{
NSString *imgExtension = [imageNamed pathExtension];
NSString *imgName = [imageNamed stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@".%@", imgExtension] withString:@""];
BOOL removedExt = [imgExtension length];
UIImage *image = [UIImage imageNamed:imageNamed];
if (IS_IPHONE_5) {
if (removedExt) image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h.%@", imgName, imgExtension]];
else image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h", imageNamed]];
if (!image) return [UIImage imageNamed:imageNamed];
} else if (IS_IPHONE_6) {
if (removedExt) image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-667h.%@", imgName, imgExtension]];
else image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-667h", imageNamed]];
if (!image) return [UIImage imageNamed:imageNamed];
} else if (IS_IPHONE_6P) {
if (removedExt) image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-736.%@", imgName, imgExtension]];
else image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-736", imageNamed]];
if (!image) return [UIImage imageNamed:imageNamed];
}
return image;
}