What's really happens when I create a "New Sprite Image" inside my Xcode images.xcassets? - ios

Days ago I asked for How check the .spriteatlas sizes generated by Xcode? but I got no answer so I decided to slightly change my question:
What happens when I choose this option here inside the images.xcassets section?
Does Xcode provide a full atlas manager and I just have to add single images inside this folder or should I put inside a whole atlas (created by my self with the .plist file attached)?

Related

Runtime warning: Could not load the image "imageName" referenced from a nib in the bundle with identifier "bundleId" [duplicate]

when I load my application it shows a warning message that
"Could not load the "" image referenced from a nib in the bundle with
identifier "
I searched and confirmed all my images. But it still shows that warning.
Select your image(s) in Project Navigator.
Open the File Inspector.
Make sure you have the target selected.
I had the same issue when I Refactor to Storyboard. Apparently the Asset catalog does not transfer the image reference. To fix, see below:
You would notice that your ImageViews is empty from reference.
1 - Click on the ImageView
2 Go to the Utilities bar where you would see you asset image is unknown
3 - Change it back to you image asset
This should fix your error. Hope this helps!
There might be many reasons of this error. To fix this issue you can just follow below given step:
Go to product menu of the Xcode, select clean.
If still you are getting the error, then remove the images from your project and again add the images to your project.
while adding image into the project, make sure that you have selected the Project name inside the "Add to targets". And also enable the "Copy items if needed".
Please Refer below image for better understanding:
Just select the image in Xcode and in right side, File inspector, under 'Target Membership' make sure your project is selected.
Another thing you can do is delete and re insert your image and make sure 'Copy items if needed' is selected and 'Add to targets' your project is selected.
Click on the image file in your Xcode navigator.
Once selected, go to the right side bar (of XCODE) which is
utilities and under file inspector, scroll to target membership and
select your project target file.
Then build and run the project again.
Xcode9 beta2 release note:
Jpeg assets in asset catalogs are not found on iOS 10 or earlier for apps built with Xcode 9. APIcalls for accessing the image such as UIImage.imageNamed: return nil. (32524123)
Workaround: Use png resources or limit app testing to devices running iOS 11 or later.
Xcode9 beta3 release note:
Jpeg assets in asset catalogs are found on iOS 10 or earlier for apps built with Xcode 9.(32524123)
For those that are getting this error while developing a cocoapod
I was trying to use an image from my pod's bundle, thats inside a .xcassets file, in the storyboard. It would show fine in the storyboard but when i ran the app it would crash saying it cant find the resource.
I changed my podspec to include s.resources as well as s.resource_bundles
s.resource_bundles = {
'SDKRes' => ['SDK/Assets/*']
}
s.resources = ['SDK/Assets/*.{xcassets}']
Then it was able to load the resource properly from the storyboard
You can try opening your storyboard or nib as Source Code and then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
I have just updated to XCode 9 and it started giving me this issue. I created a new Image Set in the Assets section and added the images I wanted to this, then re-added them to my tab bar images with custom names and it worked fine. Hope this helps!
PROBLEM
This happened to me seemingly out of the blue on a tab bar controller with icons for each tab. The storyboard was still showing my image icons and the assets existed with the expected names.
MY FIX
Select the tab bar icons in their respective view controller and reassign the image like you did the first time.
This happened to me as well. I was doing everything right when adding the image but for some reason it was not working. I had to click on the image again once added, and then on the right toolbar under "Target Membership" I noticed my project was not selected even though I was selecting it when adding the image. I selected it here and everything worked fine.
I got the same error message (in XCode 8), even though the app ran fine (in the simulator and on the device).
I found the problem: In my storyboard, using the document outline pane, I clicked through every single UIImage, and looking at the attributes inspector for each UIImage - in the Image View section - found that one UIImage had a blank file name (instead of the .png file name containing the image). Reselecting the .png file name from the dropdown box fixed the error message.
I have fetching same issue in xcode 9.
just tick on target membership
I pulled my hair out over this issue for hours and none of the solutions in this thread worked. The problem, in the end, was that the Xcode project files were stored on a Google Drive file stream. As soon as I moved it to the local drive or iCloud it worked fine.
My case was a bit different. I was using an old IBDesignable element which had some property of setting an image directly from the storyboard. Since that element was old, hidden and unused the images it had were not present in my assets folder.
Now Xcode won't be able to search this image since it is not in the project anymore. But if you search in the finder, inside your project, you'll find the XIB/Storyboard in which it is mentioned. From there you can find it manually by opening that XIB or Storyboard as source code and search. Once found either replace them with a new image or remove the unused element.
Look into storyboard file you'll see a question mark icon on any of the imageView (as shown in screenshot below) or UIButton image.
Just correct it and the warning will be gone.
Hope this helps
My guess is that you have an image in the Project Setting->Build Phases->Copy Bundle Resources which loses its reference and appears in Red text color. Remove this image from there and re-add.
This happens often due to relocate the image file after adding into project where image was added as a reference instead of a copy.
May be this can fix your issue.
Urughhh. I tried to fix this with all the above solutions, but nothing worked. What finally worked was:
Delete image from your project and select Move to Trash
Clean project
Close and restart XCode
Rename your image filename so something other than the previous name
Add new image to your project
I was facing the same problem, I solve it by deleting folder and create again and past all images then add reference again.
Based on what #hstdt posted above, it made me think I should check that my image is a filetype that doesn't have any bugs related to it. (https://stackoverflow.com/a/44558948/6804257)
I was using a .gif. I got rid of that image and instead used a .png. Now it works.
Had the same issue and none of these answers worked for me. Instead I restarted the mac and iPhone I was working with and then everything started to work fine again. 🤷‍♂️
My case is difference. I have more one assets folder. So I added to the wrong one.
Just remove and add to the right.
In my case,removing and adding the assets folder from the target fixed the issue.
Xib sets a wrong name for folder reference images. For example I have the folder like Menu->icon.png. Xib sets the "icon" name for the image. It should be "Menu/icon". So do no set images in xibs if you use a folder reference images.

Images living inside an imported pod .xcasset are selectable (and viewable) inside Interface Builder storyboard, but won't show in the simulator

I'm in the middle of some "Proof of Concept" project regarding Cocoapods, .xcassets, Swift 3, "cross-project loading images" (from pod bundles onto the main storyboard), etc...
My main problem right now is "images living inside an imported .xcasset (via pod install/update) are selectable and appear inside Interface Builder main project storyboard, but won't show in the simulator".
In runtime, the simulator running my main app yields something like this:
Could not load the "cx_green_tick" image referenced from a nib in the bundle with identifier "MyCompany.ios-appbase" when it tries to render the selected image. And then nothing appears on the expected placeholder space, just empty space.
MyCompany.ios-appbase is the bundle name of my main app.
cx_green_tick is the logical name of some image resource happily living inside my "Commons" imported project Media.xcasset folder.
This image resource consists of 3 proper .png files with their #1x, #2x, #3x names, etc...
My Commons Pod Project (the one containing the .xcasset files/folders I want to use in my main project) has a .podspec file with the following resources definition (among many other things):
s.resources = [ 'Commons/**/*.{png,jpeg,jpg,storyboard,xib,ttf,otf}' , 'Commons/**/*.{xcassets, imageset, json}' ]
Once I'm in the root folder of my main project, I just type "pod update/install" and I can see how the different pods I defined in my main app Podfile start to download and get perfectly stored into the expected Pods folder of my main project.
Then, inside Xcode, I can see how inside the Pods/Commons/Media.xcassets container there's the expected cx_green_tick image resource, with its 3 proper resolutions.
Then I change onto my main app Main.storyboard and select the cx_green_tick image resource to be used onto a UIImageView placeholder. Whenever I do it, I can see how this green tick image appears inside IB. But if I run the simulator, this image doesn't appear on its placeholder.
I'm using Swift 3.0, XCode 8, deployment target is iOS 9. All my involved Podfiles have the use_frameworks! keyword/line active.
I've REALLY been googling this for many hours (yesterday and today) but I can't see any hint on how to do it without having to do the image load by hand, programmatically. (In case it's something achievable, which I'm not really sure after all this)
BTW: If I load this image programmatically, explicitly selecting the bundle where the image resource lives inside Media.xcassets, the image appears without any problem in the simulator.
That could be a partial solution, but our main goal was not having to perform image loading by hand. Specially when (apparently) IB shows this image onto its image_name resources combo list on the top part of the screen for the UIImageView placeholder.
Any hint?
(If something is unclear, please ask and I'll try to reword it somehow )
Greetings and thanks in advance.

Could not load the "" image referenced from a nib in the bundle with identifier

when I load my application it shows a warning message that
"Could not load the "" image referenced from a nib in the bundle with
identifier "
I searched and confirmed all my images. But it still shows that warning.
Select your image(s) in Project Navigator.
Open the File Inspector.
Make sure you have the target selected.
I had the same issue when I Refactor to Storyboard. Apparently the Asset catalog does not transfer the image reference. To fix, see below:
You would notice that your ImageViews is empty from reference.
1 - Click on the ImageView
2 Go to the Utilities bar where you would see you asset image is unknown
3 - Change it back to you image asset
This should fix your error. Hope this helps!
There might be many reasons of this error. To fix this issue you can just follow below given step:
Go to product menu of the Xcode, select clean.
If still you are getting the error, then remove the images from your project and again add the images to your project.
while adding image into the project, make sure that you have selected the Project name inside the "Add to targets". And also enable the "Copy items if needed".
Please Refer below image for better understanding:
Just select the image in Xcode and in right side, File inspector, under 'Target Membership' make sure your project is selected.
Another thing you can do is delete and re insert your image and make sure 'Copy items if needed' is selected and 'Add to targets' your project is selected.
Click on the image file in your Xcode navigator.
Once selected, go to the right side bar (of XCODE) which is
utilities and under file inspector, scroll to target membership and
select your project target file.
Then build and run the project again.
Xcode9 beta2 release note:
Jpeg assets in asset catalogs are not found on iOS 10 or earlier for apps built with Xcode 9. APIcalls for accessing the image such as UIImage.imageNamed: return nil. (32524123)
Workaround: Use png resources or limit app testing to devices running iOS 11 or later.
Xcode9 beta3 release note:
Jpeg assets in asset catalogs are found on iOS 10 or earlier for apps built with Xcode 9.(32524123)
For those that are getting this error while developing a cocoapod
I was trying to use an image from my pod's bundle, thats inside a .xcassets file, in the storyboard. It would show fine in the storyboard but when i ran the app it would crash saying it cant find the resource.
I changed my podspec to include s.resources as well as s.resource_bundles
s.resource_bundles = {
'SDKRes' => ['SDK/Assets/*']
}
s.resources = ['SDK/Assets/*.{xcassets}']
Then it was able to load the resource properly from the storyboard
You can try opening your storyboard or nib as Source Code and then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
I have just updated to XCode 9 and it started giving me this issue. I created a new Image Set in the Assets section and added the images I wanted to this, then re-added them to my tab bar images with custom names and it worked fine. Hope this helps!
PROBLEM
This happened to me seemingly out of the blue on a tab bar controller with icons for each tab. The storyboard was still showing my image icons and the assets existed with the expected names.
MY FIX
Select the tab bar icons in their respective view controller and reassign the image like you did the first time.
This happened to me as well. I was doing everything right when adding the image but for some reason it was not working. I had to click on the image again once added, and then on the right toolbar under "Target Membership" I noticed my project was not selected even though I was selecting it when adding the image. I selected it here and everything worked fine.
I got the same error message (in XCode 8), even though the app ran fine (in the simulator and on the device).
I found the problem: In my storyboard, using the document outline pane, I clicked through every single UIImage, and looking at the attributes inspector for each UIImage - in the Image View section - found that one UIImage had a blank file name (instead of the .png file name containing the image). Reselecting the .png file name from the dropdown box fixed the error message.
I have fetching same issue in xcode 9.
just tick on target membership
I pulled my hair out over this issue for hours and none of the solutions in this thread worked. The problem, in the end, was that the Xcode project files were stored on a Google Drive file stream. As soon as I moved it to the local drive or iCloud it worked fine.
My case was a bit different. I was using an old IBDesignable element which had some property of setting an image directly from the storyboard. Since that element was old, hidden and unused the images it had were not present in my assets folder.
Now Xcode won't be able to search this image since it is not in the project anymore. But if you search in the finder, inside your project, you'll find the XIB/Storyboard in which it is mentioned. From there you can find it manually by opening that XIB or Storyboard as source code and search. Once found either replace them with a new image or remove the unused element.
Look into storyboard file you'll see a question mark icon on any of the imageView (as shown in screenshot below) or UIButton image.
Just correct it and the warning will be gone.
Hope this helps
My guess is that you have an image in the Project Setting->Build Phases->Copy Bundle Resources which loses its reference and appears in Red text color. Remove this image from there and re-add.
This happens often due to relocate the image file after adding into project where image was added as a reference instead of a copy.
May be this can fix your issue.
Urughhh. I tried to fix this with all the above solutions, but nothing worked. What finally worked was:
Delete image from your project and select Move to Trash
Clean project
Close and restart XCode
Rename your image filename so something other than the previous name
Add new image to your project
I was facing the same problem, I solve it by deleting folder and create again and past all images then add reference again.
Based on what #hstdt posted above, it made me think I should check that my image is a filetype that doesn't have any bugs related to it. (https://stackoverflow.com/a/44558948/6804257)
I was using a .gif. I got rid of that image and instead used a .png. Now it works.
Had the same issue and none of these answers worked for me. Instead I restarted the mac and iPhone I was working with and then everything started to work fine again. 🤷‍♂️
My case is difference. I have more one assets folder. So I added to the wrong one.
Just remove and add to the right.
In my case,removing and adding the assets folder from the target fixed the issue.
Xib sets a wrong name for folder reference images. For example I have the folder like Menu->icon.png. Xib sets the "icon" name for the image. It should be "Menu/icon". So do no set images in xibs if you use a folder reference images.

How to localize images in xcassets folder in Xcode [duplicate]

This question already has answers here:
How to localize the images in Images.xcassets?
(6 answers)
Closed 7 years ago.
I have two targets in XCode. These are two products based on the same code base but some graphics are different. It's like white labeling. The images are stored in an xcassets folder. How do I localize this? Either localizing for a language or localizing per target is fine with me as the white labeling is per language actually.
I have checked in xcassets but I don't see an option to localize any image.
update: i think one way i could accomplish this is to create a new xcassets folder for my target so it might be called images-mytarget.xcassets. then in the target build phase i could alter the xcassets folder in the 'copy bundle resources' area to use my targets xcassets. I was able to do this successfully. This differentiates xcassets per target. resolved.
While there's (apparently) not currently a way to explicitly localize the xcassets file directly, you could localize the name of the asset to pull using your Localizable.strings file. For instance, say you have a graphic logo treatment for the main menu of a game that needs to be localized. You could put the localized logo treatments in the assets file with different names, add the names to your Localizable.strings file, and then fetch the appropriate image with code like this:
UIImage *img = [UIImage imageNamed:NSLocalizedString(#"MAIN_MENU_IMAGE", nil)];

Full screen issue after manually creating an empty application in Xcode 6

Since xcode 6 didn't offer an empty application any more, I manually created one by deleting the Launch screen interface file and the Main storyboard file base name in the info.plist file, and deleted Main.storyboard and LaunchScreen.xib then. Considering that I'll drawing the UI by myself, I created a view controller without an xib file. But when I ran the app, there are black bars both on the top and the bottom. I checked the [[UIScreen mainScreen]bounds] and found out that the bounds was 480*320.
I've checked on google and there were suggestions like adding png pictures or creating a xib file, but I really wonder why the property bounds didn't get the right size.
I have met with this problem, it's because you delete your "Launch screen file" and didn't set in general tab "Launch image source".
So you need to make .xcassets file, after right click inside .xcassets file you create "New Launch Image" with name something like "LaunchImage" and set images for appropriate sizes. After that in general tab you set "Launch image source" property name with your "LaunchImage".
Step 1:
Step 2:
Step 3:
A better approach would be to keep the storyboard and everything else Xcode sets up for a single-view app, and then build out your UI programmaticly from the ViewController. That way, you inherit all the automagic stuff the SDK does during startup.
I can't tell you exactly what this automagic stuff is; but, I'm pretty sure your bug would go away if you adopted this approach.

Resources