0
如何根據字符串判斷圖像是否存在於主應用程序包中?例如,包中是否存在名爲image1.png的圖像?iOS - 檢查圖像是否存在於應用程序包中
如何根據字符串判斷圖像是否存在於主應用程序包中?例如,包中是否存在名爲image1.png的圖像?iOS - 檢查圖像是否存在於應用程序包中
NSBundle方法:
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension
將返回nil,如果沒有圖像被發現。
即
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" [email protected]"png"];
if(filePath.length > 0 && filePath != (id)[NSNull null]) {
UIImage *myImage = [UIImage imageWithContentsOfFile:filePath];
}
感謝。如果我找到它,如何獲得圖像,因爲該方法只是返回一個字符串? – soleil
[UIImage imageWithContentOfFile:yourFilePath]; – J2theC
我更新了我的答案。 – ohr