2倍圖3倍圖的用法之前一直用的很混亂,自己寫了個例子來驗證了一下,現在寫出來吧。
UIImage的加載有兩種方法
[UIImage imageNamed:@"small cat"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"smallcat" ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
1.imageNamed
1.1 在@x,@2x,@3x都存在的情況下:
iPhone4s,5,6,6s,7優先加載@2x的圖片
iPhone6p,6sp,7p,優先加載@3x圖片
1.2 在只有@1x和@3x的情況下:
iPhone4s加載@1x的圖片
iPhone5,6,6s,6p,6sp,7p,優先加載@3x圖片
2.ContentOfFile
2.1 在@x,@2x,@3x都存在的情況下:
同imageNamed方法的加載規則
iPhone4s,5,6,6s,7優先加載@2x的圖片
iPhone6p,6sp,7p,優先加載@3x圖片
2.2 在只有@1x和@3x的情況下:
iPhone4s,5,6,6s,7優先加載@x的圖片
iPhone6p,6sp,7p,優先加載@3x圖片