2014-11-13 56 views
1

因此,我製作的應用程序有很多圖像,我用於UI,但我遇到了@ 1x,2x和現在我正在嘗試設置幀的3倍概念。使用新的@ 3x幀適當地構圖圖像

所以第一關,我寫了含有一種叫getDevice這樣我就可以判斷用戶正在使用設置正確的框架爲每個元素是什麼設備功能的全局函數庫:

//Device 
+ (int)getDevice 
{ 
    CGSize bounds = [[UIScreen mainScreen] bounds].size; 

    if((bounds.width == 320 && bounds.height == 480) || (bounds.width == 480 && bounds.height == 320)) 
     return gDevice_iPhone4S; 
    else if((bounds.width == 320 && bounds.height == 568) || (bounds.width == 568 && bounds.height == 320)) 
     return gDevice_iPhone5; 
    else if((bounds.width == 375 && bounds.height == 667) || (bounds.width == 667 && bounds.height == 375)) 
     return gDevice_iPhone6; 
    else if((bounds.width == 414 && bounds.height == 736) || (bounds.width == 736 && bounds.height == 414)) 
     return gDevice_iPhone6Plus; 
    else if((bounds.width == 768 && bounds.height == 1024) || (bounds.width == 1024 && bounds.height == 768)) 
     return gDevice_iPad; 

    return gDevice_Unknown; 
} 

這一切運作良好,但是我的問題圍繞着框架大小,現在我可以識別出正確的設備。所以,舉個例子,假設我有三個按鈕,我想跨越屏幕的底部。在iPhone 4S上,這將是這樣的:

iPhone 4S

現在,這是使用3張圖片:

但是,當我想上的IP使用這些照片,會發生什麼磨練6?

iPhone 6

現在這個應該使用相同圖片,沒錯,自從iPhone 6仍然使用@ 2倍?

但隨後(220x80)需要成爲(258x94)這將拉伸圖像。那麼,當我需要@ 1x,@ 2x,@ iPhone62x和@ iPhone6Plus3x時,擁有@ 1x,@ 2x和@ 3x iPhone圖像有什麼意義?

回答

1

是的,乍一看有點令人困惑。

對於iPhone 4/4s/5/5s和iPhone 6而言,擁有@ 2x的觀點就是這些屏幕的DPI相等(326 ppi)。

在另一方面,你有這些iPhone手機不同的圖像需要的是特定於您的應用程序的設計和你有以下解決方案:與-resizableImageWithCapInsets:

  • 使用伸展的形象創造,使圖像尋找既爲好110pt和129pt
  • 或者,如果無法使用不同的圖像,取決於運行的設備應用程序。您可以使用方法+getDevice(或類似)來確定應加載的圖像([email protected][email protected])。

欲瞭解更多信息和方便UIImage類別看這個答案https://stackoverflow.com/a/26684508/753878