iOS: How to use images in custom bundle in Interface Builder? - iphone

I have a bundle where i put images in it.
The contents are:
MyBundle.bundle/images/picture1.png
MyBundle.bundle/images/picture2.png
I dragged MyBundle.bundle into my project.
Now I can see these images in Interface Builder and can even use them. However, when I run the app, I don't see the images.
What's wrong?
Thanks,

Make sure the bundle is getting copied over in the "Build Phases" of the project settings for the target.
Also, try setting them progrmatically and see if they show:
myImageView.image = [UIImage imageNamed:#"MyBundle.bundle/images/picture1.png"];
I just tried this in my project and found that what you need to do is specify the image with the bundle name in front like this:
In the IB the image will look broken:
but when you build and run your project the image will show correctly.
So, in your case, use MyBundle.bundle/images/picture1.png in the actual Interface Builder Image box.
Also, when you dont put the bundle name in front, you get this warning when you load the view with the bundle image:
2011-10-12 08:22:16.360 UTDebug[721:11c03] Could not load the "map.png" image referenced from a nib in the bundle with identifier "com.companyname.myproject"

You need to put the XIB in the bundle, too. When you do that, resources for the interface will be relative to the bundle, so they'll work both in IB and when you load the interface in your app.

You might have a stray build setting from having created the bundle as a Mac OS X target.
See my other answer for the solution.

Related

Why image not shown in simulator when using XIB designable?

Currently i'm trying to change icon image from designables image
I have main project with bundle com.abc.def (firstbundle)
I put the image on another bundle com.abc.ghi (another framework connected to main project)
When i set the image on viewcontroller (in the first bundle), the image shown in the interface builder. (2nd image)
But when i run it on simulator, the image is not shown. And there is error in console
Could not load the "hide" image referenced from a nib in the bundle with identifier com.abc.def -> This error means, xcode try to find image from first bundle not from second bundle. How to make it also check image from second bundle ?
The problem is only if i using designable option from XIB. If i'm not using it, just define directly inside source code "remove #IBInspectable from the 1st image" (from another bundle). The image shown correctly

Could not load the "block" image referenced from a nib in the bundle with identifier - can't access image in other bundle

I got error Could not load the "block" image referenced from a nib in the bundle with identifier while trying to set image from from .xib file in one module, which (image) reside in another module. I'm trying to set image for a UIButton (not an UIImageView)
I've seen this iOS: How to use images in custom bundle in Interface Builder?
Article but it wasn't helpful.
I've tried
MyBundleName.bundle/iconName
MyBundleName/iconName
MyBundleName.bundle/Resources/Assets/Images.xcassets/iconName
I putted that in .xib GUI (when you suppose to set image for UIButton) but didn't succeed
In fact, in preview (.xib file in XCode) everything is nice, but after i visit the screen it doesn't work (and i see error i specify in article name in console)

Why does resource bundle copy .png as .tiff images?

I've created a static library and a resource bundle for reusing code and assets across several projects.
Within the static library, I have a manager class whose sole purpose is to create other UIViewControllers, whose views are created from .xib files (using the common initWithNibName:bundle: method).
When I create the view in Interface Builder, the images show correctly. However, when I run the app on the simulator, I get this error:
Could not load the "<image_name.png>" image referenced from a nib in the
bundle with identifier "com.<my_company>.<app_identifer>"
After hours of grinding, I finally inspected the resources bundle, and I found that the .png files weren't in it! Instead, .tiff files of the same name (excluding #2x versions) were there instead.
All of the images are included within the bundle's build phase under copy bundle resources , and I've used the images on other iOS projects (so they're not corrupted).
Has anyone else experienced this? Is it safe to assume that the images will always be added to the bundle as .tiff? (And if so, is it safe to just change the image name in interface builder to .tiff?) Or am I doing something incorrect here?
Thanks for your help in advance.
For the issue of resource bundles , refer to this link as it has a couple of similar faced queries.
Conversion Resource bundle
Tell me which answer really helped you solve this issue. Thanks.
This Solved my problem
In your bundle target Go to,
Build Settings > COMBINE_HIDPI_IMAGES and set to NO

Core-Plot: Unknown class CPLayerHostingView in Interface Builder file

Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.

Images in Interface Builder when using MonoTouch

I'm new to MonoTouch and iPhone development. I have my images (PNG) in a resources folder in MonoDevelop, however if I want to set the image property for a button in Interface Builder, how do I do that? It's always a blank dropdown. Do I need to use XCode to access the XIB file and then somehow embed the button image file I'll need in it?
This is a known limitation of MonoDevelop and Interface Builder. To add images to an XIB in Interface Builder they must be part of an XCode project, which of course coming from MonoDevelop they're not.
To achieve what you're trying to do you will need to set the image via code, and ensure the build action of your image is set to Content. To do this, simply right click your image inside MonoDevelop, and select Build Action > Content.
On your view with the button on it, create an outlet in Interface Builder for your button, hook it up, then from code to set your image, you just need to use the .FromFile("path/name") method of UIImage.
UIImage buttonImage = UIImage.FromFile ("resources/image.png");
myButton.SetBackgroundImage (buttonImage,UIControlState.Normal);
That's off the top of my head, but I think that should do it.
You can manually set the image in Interface Builder, but it wont show up until run time. The image name can include a path, e.g. "images/settings.png".
All solutions given here are completely wrong and misleading. All you need to do, is place your images in the Resources folder (on the project root), and add your images to this folder. After adding files to this folder, mark all files and make sure their build action is set to BundleResource.
I also needed this to work, here is a workaround I found.
You need to create a dummy xcode project. Place it in the same folder as your project.
Add all your xib files and image files to that xcode project by dragging them in when the project is opened in xcode. Now you will be able to see the preview of the images.
The image files must be in the same folder as the project file and xcode must be opened with the dummy project while the interface builder is opened.
Not great - but solves the issue for now.
Here is a sample project I have created.
For this issue to be resolved on the MonoDevelop side - some inter-process communication code needs to be created, I think that a good starting point will be looking for "PBXProjectWatcherServerConnection-3.1.2" in google.