我是iOS編程新手。我想問這些關於不同屏幕尺寸的圖像大小的問題不同iOS設備的圖像大小
- 對於所有iOS設備,x,2x和3x圖像大小是否足夠?我的意思是,如果我有一個名爲「background.png」的圖像,background.png,background2x.png和background3x.png是否足以適用於所有iOS設備/屏幕尺寸?
- 如果不是,不同的iPad型號是否需要其他圖像尺寸(x,2x和3x除外)? .......一個解釋不同的屏幕尺寸/設備的圖像大小的鏈接將不勝感激。由於
我是iOS編程新手。我想問這些關於不同屏幕尺寸的圖像大小的問題不同iOS設備的圖像大小
是X,2倍和3個的圖像尺寸是必要的開發應用爲所有iOS設備,但圖像的尺寸可以爲iPad & iPhone設備不同,這取決於iPad的& iPhone應用程序的用戶界面。
爲背景圖片更好的理解,請看看Adaptivity and Layout
一個與您查詢的最佳文章 - Adaptive Layout Tutorial in iOS 9: Getting Started
如果您對@ 1倍,@ 2X形成的圖像,並@ 3倍,名稱他們是這樣的:
myImage.png
[email protected]
[email protected]
[email protected]
[email protected]
然後,你可以調用像吹製法:
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;
}