Reputation: 4648
The following code returns an image object from path
and works previous to iOS 11:
NSString *path = [anotherPath stringByAppendingPathComponent:file];
UIImage *image = [UIImage imageNamed:path];
However in iOS 11, image
returns null
. Is this an iOS 11 bug?
Upvotes: 1
Views: 385
Reputation: 4648
As @drewster pointed out, the path was incorrect; I had a lower case character. However, I noticed iOS 8 ignored this.
Upvotes: 0
Reputation: 185671
+[UIImage imageNamed:]
is documented as taking a filename, not a path. If you want to load an image from a path, use +[UIImage imageWithContentsOfFile:]
.
If your path here is referring to something in a nested folder in your bundle, you can ask NSBundle
for the path for the resource and then pass that to +[UIImage imageWithContentsOfFile:]
. This would look like
NSString *path = [NSBundle.mainBundle pathForResource:@"foo" ofType:@"jpg" inDirectory:@"dir"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
Upvotes: 1