1. 程式人生 > >iOS 中@2x 和 @3x 圖片載入問題

iOS 中@2x 和 @3x 圖片載入問題

使用initWithContentsOfFile可以優先選擇3x影象,而不是2x影象。

NSString *path = [[NSBundlemainBundlepathForResource:@"smallcat"ofType:@"png"];

UIImage *image = [[UIImagealloc]initWithContentsOfFile:path];

在ipone5 s、iphone6和iphone6 plus都是優先載入@3x的圖片,如果沒有@3x的圖片,就優先載入@2x的圖片

這個方法

[UIImageimageNamed:@"smallcat"]

iphone5s和iphone6優先載入@2x的圖片,iphone6 plus是載入@3x的圖片。