I have an array:
langArray = [[NSMutableArray alloc]initWithObjects:#"Italiano",#"English",#"Francais", nil];`
and cell image like this :
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"language_%#_disabled.png",[langArray objectAtIndex:indexPath.row]]];
but images don's display in device, in simulator they display normally.
Check the images name in your Xcode Project..
Because simulator is Case Insensitive and Device is Case Sensitive..
May be the ImageName in your array different Imagename in your local. You can check upcapercase
Check in your Xcode project source may be your image extension is
".PNG" rathere then ".png"
Related
Today when I search some information about #1x #2x #3x
something confuses me
are these only used as app icon? Because most messages always give me the example of the icon.
and If it can be used in app view, how is the code?
like this?
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"background.png"]];
Then, iOS will change #1x and #2x itself? OR I need to code like this:
#define deviceIsIPhone5 ([UIScreen mainScreen].applicationFrame.size.height == 568 ? YES : NO)
if (deviceIsIPhone5)
{
self.backgroundImage.image = [UIImage imageNamed:#"background#2x.png"];
}
else
{
self.backgroundImage.image = [UIImage imageNamed:#"background.png"];
}
You don't have to think about #2x #3x.iOS automatically handles it.
All you need to care about is to put right size image into the right box(.xcassets) if you want to show image properly in all iOS devices.
no need to care about 2x,3x and png.
just enter image name only. ios will automatically check image to use according to screen dimensions.
self.backgroundImage.image = [UIImage imageNamed:#"background"];
I'm trying to load a launch image from the Image.xcassets folder but to no avail. There are other answers (and this one) on SO that purport to answer it but their main solution, to simply load an image like so
UIImage *image = [UIImage imageNamed:#"Default#2x"];
returns nil for me.
The filename is named correctly and the project is setup to use the assets.
Does anyone have any idea how I do this or what I could be doing wrong?
Thanks in advance.
EDIT:
EDIT 2: my final code:
-(void) loadSplashImage{
if ([self isiPad]){
self.imageViewSplash.image = [UIImage imageNamed:#"Default-Portrait"];
}
else{
if (self.view.frame.size.height == 480){
self.imageViewSplash.image = [UIImage imageNamed:#"Default"];
}
else if (self.view.frame.size.height == 568){
self.imageViewSplash.image = [UIImage imageNamed:#"Default-568h"];
}
else if (self.view.frame.size.height == 667){
self.imageViewSplash.image = [UIImage imageNamed:#"Default-667h"];
}
}
}
Please note it works for Portrait only.
You dont have to specify the size of the image in your name. It will automatically load the size that best fits for the device that runs the app. So your code should be.
UIImage *image = [UIImage imageNamed:#"Default"];
where default is the name of the resource from xcassets, the one you see on the leftside list.
Here's the way to get LaunchImage name.
Xcode 5 & Asset Catalog: How to reference the LaunchImage?
Getting image name from info.plist ([[NSBundle mainBundle] infoDictionary])
You should have 2 files:
(1) Default.png (or any other image format) — Non retina
(2) Default#2x.png — Retina
Now, to get this image, you will not have to use #2x at the end of the file name. Use just name of that image asset.
Is there a way I can say for a particular UIImageView:
UIImageView *imageView = <#instantiate#>
imageView.image = #"someImageFromImageAsset";
and based on the device it's rendering on, it sets the right image. Obviously I need to set the image for a particular device but I am unsure how you do it.
iOS will automatically choose the correct sized image if you just use the name of the image. Use #2x in the image file name for retina display.
Objective-C
imageView.image = [UIImage imageNamed: #"someImageName"];
Swift
imageView.image = UIImage(named: "someImageName");
I build my project using iOS 7.1 and try to load UIImage view with image that is stored in the /images/cars/car_1.png
All images are located in the folder images as on picture below in project tree:
So it works perfect for iOS 7.1 and Xcode 5, but when I try to use Xcode 6 and iOS 8 the UIImage instance is equal nil when I try crate image.
UIImage *image = [UIImage imageNamed:#"/images/cars/car_1.png"];
po image
nil (for iOS 8)
it can be also
UIImage *image = [UIImage imageNamed:#"/images/sport-cars/car_1.png"];
as you can see the name of resources is the same car_1.png but it is ok because they are in different resources folders not in the bundle folders.
Ok the problem is that on the simulator and seems on the device as well by some reason when we use #"/Reference Folder Path/image.jpg" it won't work.
Removing this "/" at start of path solve this issue.
You can check this video to see how it works.
On iOS 4 and later, if the file is in PNG format, it is not necessary
to specify the .PNG filename extension. Prior to iOS 4, you must
specify the filename extension.
So the answer is you have to specify the filename extension for all JPEG.
If this not solve your problem, Try this
Instead of using the imageNamed you can load the image with the methods imageWithContentsOfFile
NSString *imageFile = [NSString stringWithFormat:#"%#/iphone4/%#", [[NSBundle mainBundle] resourcePath], #"1.png"];
UIImage* image = [UIImage imageWithContentsOfFile:imageFile];
NSString *imageFile1 = [NSString stringWithFormat:#"%#/iphone5/%#", [[NSBundle mainBundle] resourcePath], #"1.png"];
UIImage* image1 = [UIImage imageWithContentsOfFile:imageFile1];
NSString *imageFile2 = [NSString stringWithFormat:#"%#/iphone6/%#", [[NSBundle mainBundle] resourcePath], #"1.png"];
UIImage* image2 = [UIImage imageWithContentsOfFile:imageFile2];
I have added 3 folders (with same image name and extension) in my project. I am able to fetch them differently and it work fine
I want to add UIImage on button,but the del.png can't show on my button,
What can i do?
I try many load Image Method,but no effect,such as:
UIImage* delImage = [[UIImage alloc] initWithContentsOfFile:#"del.png"];
UIImage* delImage = [UIImage imageNamed:#"del.png"];
UIImage* delImage =[UIImage imageWithContentsOfFile:#"del.png"];
CalDelBtn *BookItem = [[CalDelBtn alloc] initWithFrame:CGRectMake(startPointX, startPointY, 75, 113) statuePicture:delImage];
Please give me some advice,thank you!!
First, you image could be loaded with
UIImage * image = [UIImage imageNamed:#"del.png"];
This is the simplest way to load an image, so it should work with an autoreleased image.
Don't forget to add it to your xCode projet explorer! Here's a list of reasons for what your image generally woudn't display : https://stackoverflow.com/a/9698764/127493.
Then, add it to your button with :
[button setBackgroundImage:image forState:UIControlStateNormal];
for example. Does it work ?
Can you verify that your image is being added to your target? Xcode 4.3 has a nasty habit of not including files into targets when you drag and drop. So click on your project file on the left side of Xcode, go to Build Phases and see if your image is in the list under Copy Bundle Resources.