2014-10-02 73 views
8

如何設置相應的MYimage.pngMyimageView在Xcode 6與ios 8.x兼容性。iphone 6 vs iphone 5 image命名約定

MyimageView setImage:[UIImage imageNamed:@"MYimage.png"]; 

在資源,我有分辨率以下圖片:

MYimage.png--320*480 

[email protected]*960 

[email protected]*1136 

[email protected]*1334 

[email protected]*2208 

對於iPhone 4S,它表明:[email protected] [Right]

對於iPhone 5S,它表明:[email protected] [wrong]

對於iPhone 6,顯示:[email protected] [wrong]

對於iPhone 6 +,它示出了:[email protected] [wrong]

但是重命名圖像之後如下所述:

MYimage.png--320*480 

[email protected]*960 

[email protected]*1136 

[email protected]*1334 

[email protected]*2208 

對於iPhone 4S,它示出了:[email protected] [Right]

對於iPhone 5S,它示出了:[email protected] [wrong]

對於iPhone 6,它顯示了:[email protected] [wrong]

對於iPhone 6 +,它示出了:[email protected] [Right]

那麼,實現的格式是什麼?

注:另外一派以下Links等..

+0

尺寸符號不應超過.png擴展名嗎? TBH,我從來沒有聽說過除了啓動圖像以外的任何其他尺寸符號。 – brandonscript 2014-10-02 12:42:58

+0

@remus你能詳細說明'尺碼符號'嗎? – 2014-10-02 12:47:51

回答

9

的iOS只支持大小爲符號發射的圖像,例如this頁描述3.5" 用法,4" ,和iPad格式[email protected],等等。

實際上您只能支持的是@ 2x和@ 3x(請參閱here),它解釋了爲什麼在您看到的每個設備上只能選擇@ 2x和@ 3x png。

最後,[email protected]*h也不是有效的尺寸表示;當您引用名爲MYimage.png的圖像時,系統不會自動讀取這些文件;最多可以做[email protected][email protected]

下面回答你的問題:

iPhone 6和iPhone 5都在相同像素密度呈現。 UI元素應該在兩個設備上的相同點大小的UI中正確定位。

例如:

iPhone 5  iPhone 6 
|  |  |  | 
|  |  |  | 
|  |  |  | 
|[bttn]|  |  | 
|______|  | [bttn] | 
       |________| 

如果你雖然顯示在一個UIImageView的照片,你可以創造最大的尺寸,讓它無論是縮減到了iPhone 5(使用UIViewContentModeScaleAspectFill)或將其按原樣(使用UIViewContentModeCenter)。

最後,你真的不想必須爲每一個設備管理的具體尺寸在那裏 - 已如果你是其中2高分辨率資產的每個元素,這是一個很大的存儲空間。爲每個設備添加一個是不必要的,蘋果從來沒有打算這樣做。

+0

那麼如何爲iphone 5和iphone 6使用不同大小的圖像。載入唯一名稱(nativescale)是唯一的解決方案? – 2014-10-02 12:52:31

+0

見編輯回答。 – brandonscript 2014-10-02 12:57:43

+0

「iOS僅支持啓動圖像的大小符號」 - 這是不正確的。如果您調用'[UIImage imageNamed:@「foo」]',iOS將根據平臺加載foo.png,[email protected],foo〜ipad.png或[email protected]~ipad.png。正如你所說,啓動圖像也支持'Default-536h @ 2x.png'(4「/ iPhone5) – Olie 2015-02-11 22:35:38

9

您不需要指定圖像的屏幕尺寸,但只需指定它的密度。

有3個密度基團:

  • 1X:iPhone 3GS和以前; iPod Touch第三代和以前; iPad 2和以前; iPad Mini 1st Gen;
  • 2x:iPhone 4,4S,5,5S和6; iPod Touch第4代和第5代; iPad 3和更新; iPad迷你第二代;
  • 3x:iPhone 6 Plus;

對於每個組,您應添加一個圖案名爲"[email protected]"的圖像,其中密度可以省略1x。

例子:

爲了您的圖像資源,更好地利用和組織,你應該考慮使用Asset Catalogs。它們還將幫助您瞭解您需要的圖像大小,具體取決於您將支持的設備,而且您不需要關心每個單獨的文件名。

+0

iPhone SE,iPhone 6S,7應該被添加到2x組,而iPhone 6S Plus和7 Plus以及iPad Pro應該被添加到3x組。 – Raptor 2016-09-13 09:44:42