문제

How can I tell if an image is present in the main app bundle based on a string? For example, is there an image called image1.png in the bundle?

도움이 되었습니까?

해결책

NSBundle method:

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

will return nil if no image was found.

i.e.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" ofType@"png"];
if(filePath.length > 0 && filePath != (id)[NSNull null]) {
   UIImage *myImage = [UIImage imageWithContentsOfFile:filePath];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top