2013-03-08 65 views
1

我正在爲iPhone 4和iPhone 5兼容應用程序。對於設置圖像我使用的代碼: [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aaaa" ofType:@"png"]]]imageWithContentsOfFile不適用於iPhone 5

  1. 它工作正常的iPhone 4模擬器和設備,但iPhone5的模擬器不起作用。我還沒有iPhone 5。任何機構都可以告訴我,它可以在iPhone 5設備上工作嗎?

  2. 如果我爲iPhone 5使用的圖像使用了不同的名稱,並且我不能使用圖像名稱寫@ 2x,那麼[UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aaaa" ofType:@"png"]]]可以很好地工作在onphone 5模擬器上。任何機構都可以告訴我,它是否也適用於iPhone 5設備?

  3. 或者是否有任何其他出路使用[UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aaaa" ofType:@"png"]]]在iPhone 5上設置圖像。

請建議。

謝謝。

+0

只是嘗試打印資源路徑[一個NSBundle mainBundle] pathForResource:@ 「AAAA」 ofType:@ 「PNG」],並確保它不是零 – prasad 2013-03-08 15:25:29

+0

其打印路徑。適用於iPhone 4.如果我在代碼中將圖像名稱寫爲[email protected],則適用於iPhone 5。 – NiKKi 2013-03-11 07:39:11

回答

0

是的。這也適用於iPhone 5設備。只需以不同的名稱複製圖像。

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
{ 
    CGSize result = [[UIScreen mainScreen] bounds].size; 
    if(result.height == 568) 
    { 
     // iPhone 5 
     [appConfig setLogoURL:[NSString stringWithFormat:@"%@%@", @"file://localhost", [[NSBundle mainBundle] pathForResource:@"header5" ofType:@"png"]]]; 
    } 
    else { 
     [appConfig setLogoURL:[NSString stringWithFormat:@"%@%@", @"file://localhost", [[NSBundle mainBundle] pathForResource:@"header" ofType:@"png"]]]; 
    } 
} 
else { 
     [appConfig setLogoURL:[NSString stringWithFormat:@"%@%@", @"file://localhost", [[NSBundle mainBundle] pathForResource:@"header" ofType:@"png"]]]; 
} 
相關問題