I have a custom Resource bundle where i'll have all my images and localization files inside it.
When I assign some images in xib I have to type the entire path where image resides inside my bundle for example MyResource.bundle/Images/Event/xxx.png.
Which means in xib it always taking apps main bundle for images.
Here my question is is there any possibility is there like I can change the default bundle preference to MyResource.bundle/Images So that I can see the image in xib when assigning to a uiimageView or any other.
preference? in simple words its not possible because there is no property like that, so you need to find out a way to achieve this, but i have used bundle for resources but not have this kinda problem because bundle is logical path
My solution is add one image manager to manage your image resource. I mean when you need an image, you just call your manager's method passing in the image name. And your image manager will read the correct image file from corresponding bundle and return it based on device's language.
Related
I have a launchscreen with a image, so far working well.
But now I have 3 schemas: dev, hom and prod.
I would to know how to change the launch screen image according the schema selected at the build time?
EDIT
I have in mind two options, but I do not know which one is best:
Option 1: Create two storyboards and create a variable to set the name of the correct storyboard in the app delegate. This variable I will use in the Info.plist key (Launch screen interface file base name).
Option 2: Create two scenes at the Launchscreen.storyboard and programatically set the correct scene according the enviroment.
Use targets, add a target for each environment, each target will have its own info.plist and you just set a different launch screen storyboards for each target , set it once in the relevant info.plist and you ready to select any target and run.
Your second option definitely won't work, since you cannot execute any code on a LaunchScreen and the LaunchScreen is displayed before any code could be executed (even in your AppDelegate), so you cannot change the LaunchScreen file in runtime.
Your first option is almost correct. Indeed a viable solution could be creating several Storyboards for the different launch screens, but you need to tweak the Info.plist file in a build script, you cannot do this in runtime either. Be aware that I haven' actually tested this method, but in theory it should work.
In my iOS project, I creat a xcasset named:PaoPaoImages.xcassets
then I put all images into PaoPaoImages.xcassets.
And I have a xib file named:a.xib, I compile it into a.nib.
Then I put a.nib into a bundle named:paopao.bundle.
So, now, my images in PaoPaoImages.xcassets , and my nib in PaoPao.bundle. And the nib reference the images.
Then, I run my project, the nib cannot show the images.
I'm stumped... any advice?
In order to access the image from the Asset Catalog, you only need to access the name of the asset group without any extensions.
So, if you add an image named #"my-button#2x.png" to the Asset Catalog, it will create an asset group called my-button.
Now, all you have to do is access the image like so:
In coding use following line
[UIImage imageNamed:#"my-button"];
instead of
[UIImage imageNamed:#"my-button.png"];
Also, you can edit the asset group by renaming it (without renaming the images) or changing it's individual components. This will allow you to follow easier naming conventions as well as show completely different assets between different UIScreen scales without any scale checks.
In order to incorporate images for different device sizes, you may need to toggle it under the "Devices" subheading in the Asset Catalog Group's options.
==> check here code try it:-
NSBundle *myImageBundle=[NSBundle bundleWithPath: myBundlePath];
NSArray *ImageURLs=[myImageBundleURLsForResourcesWithExtension:#"png" subdirectory:nil];
NSLog(#"imageURLS: %#",ImageURLs);
=>here refrence more try it:-
Access Asset Catalog programmatically
Load image from bundle with IOS
I have two nib files that use the same image, but I want to call the image nib_a_image.png when I reference it from nib a, and nib_b_image.png when I reference it from nib b.
The idea is that my designers could give me a new nib_a_image.png and only affect behavior of nib a.
But I don't want to increase the size of my app by including the image multiple times.
Would symlinks work? Sounds like symlinks would work. Not sure I love the idea.
Has anyone tried to do something like this?
I have an imageview in the center of the screen defined in a xib file
several runs ago -> the image displayed and everything was ok
Now, for some reason, the image is visible in the interface builder, but is not there at runtime
I've tried with and without constraints
I triple checked that the image it displays is there in the project bundle
The image property hidden is set to NO
what could cause the image NOT to display at run time ?
with a curious thing: in the next screen the image IS there
It turned out to be a localization issue. It seems that if i load the xib file from a specific bundle, and not the main bundle. It wont be able to find the images of it, if the images are not localized as well
I'm loading an image into my UIView background as a background color from a file stored in my xcode project. It works fine on the iPhone simulator but when I compile on my iPhone, the image isn't there in the background, which is obviously due to the fact that the image isn't stored as a file on phone. Is there a way to hard code an image so it's transported to different devices, forgoing the need to have an image file present?
When dragging a image(or any other reseources), be sure to check this option: Copy items into destination group's folder. In this way, your image will be store in the app bundle, instead to just reference from some path inside your pc.
Here's of this checkbox:
Have you tried
adding the image to the bundle in the copy files build phase?
This will put the image into your app so it will always be there.
Image load important point:
1.Make sure your image below your project document, the true path or relative path.
2.Image name differentiate uppercase and lowercase on the iphone but not use the iphone simulator.
3.Use Xcode shotcuts 'command+shift+K' to clear your project then run again, judge for if the image cached or not.
Run run run!
Happened to me once as well. Remember that if you're using [UIImage imageNamed:#"imageName"];, then with the iOS simulator, you don't need the letters to be in the right case. If your image is named "IMAge.png", then the simulator would find it with the parameter "image.png", but the device wouldn't. So make sure you've got the correct name, the device is case-sensitive.