Reputation: 1076
This is the basic code I use to add an image named "Background.png" to an UIImageView:
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"Background.png"];
imageView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:imageView];
Since the last Xcode update the resource can't be loaded.
I tried running on an iPhone 6 - iOS 10.3 and the Simulator - iOS 11.0
For some reason even though the iOS deployment target is version 10.3 the simulator runs on iOS 11.0
The image is there, in the same folder as the project named: "Background.png"
I've been doing the same thing for years and now it has stoped working.
Anyone had a similar issue?
Upvotes: 2
Views: 102
Reputation: 11
I had the same problem and i solved it as follow:
Simply Select your image, then check the box linked to your projet name in "Target Membership" (on the Right Window)
is it working ? There is a Screenshot if needed: https://i.sstatic.net/gTOGJ.png
Upvotes: 0
Reputation: 13290
You may want to utilize the purpose of Assets.xcassets
. Put your assets there and you can easily use your images. Note that you do not have to put the image's file extension. It's easy, like so:
UIImage *markerImage = [UIImage imageNamed:@"marker"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:markerImage];
[imageView setFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:imageView];
I have an image in my Assets.xcassets
named marker.
Edit: this is tested, I made an Objective-c project just for this question :)
Upvotes: 1