Questions tagged [imagenamed]

imageNamed: is a method of the UIImage class in iOS. It is a convenience method for loading images without specifying any path information and storing them in a cache.

Explanation from the Apple documentation:

imageNamed: Returns the image object associated with the specified filename.

+ (UIImage *)imageNamed:(NSString *)name

Parameters

name

The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle.

Return Value

The image object for the specified file, or nil if the method could not find the specified image.

Discussion

This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

On a device running iOS 4 or later, the behavior is identical if the device’s screen has a scale of 1.0. If the screen has a scale of 2.0, this method first searches for an image file with the same filename with an @2x suffix appended to it. For example, if the file’s name is button, it first searches for button@2x. If it finds a 2x, it loads that image and sets the scale property of the returned UIImage object to 2.0. Otherwise, it loads the unmodified filename and sets the scale property to 1.0. See iOS App Programming Guide for more information on supporting images with different scale factors.

Special Considerations

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.

Availability

Available in iOS 2.0 and later.

52 questions
118
votes
2 answers

Dispelling the UIImage imageNamed: FUD

Edit Feb 2014: Note that this question dates from iOS 2.0! Image requirements and handling have moved on a lot since then. Retina makes images bigger and loading them slightly more complex. With the built in support for iPad and retina images, you…
Rog
  • 17,070
  • 9
  • 50
  • 73
56
votes
20 answers

UIImage imageNamed returns nil

I am pretty new to iOS and Xcode. I tried to load an image with [UIImage imageNamed:@"imageName.png/jpg and so on"]; but it only returns nil. The image should be in my project bundle, considering the fact that I can choose it from drag and drop…
arne somborn
  • 689
  • 1
  • 7
  • 9
23
votes
1 answer

use xcassets without imageNamed to prevent memory problems?

according to the apple documentation it is recommended to use xcassets for iOS7 applications and reference those images over imageNamed. But as far as I'm aware, there were always problems with imageNamed and memory. So I made a short test…
appsperimental
  • 297
  • 2
  • 8
21
votes
2 answers

JPG image doesn't load with UIImage imageNamed

I read on the reference that from iOS version 4.+ with the method imageNamed of UIImage object, the file extension is not required. From UIImage class reference: Special Considerations. On iOS 4 and later, the name of the file is not required to…
Rasmas
  • 211
  • 2
  • 4
12
votes
1 answer

UIImage initWithContentsOfFile doesn't work

I have question: I want to avoid [UIImage imageNamed:]. So i did: UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:@"myimage.png"]; controller.productImg.image = prodImg; [prodImg release]; But now the image is not shown anymore. Does…
Tanner
  • 133
  • 1
  • 2
  • 5
12
votes
6 answers

How to get [UIImage imageWithContentsOfFile:] and High Res Images working

As many people are complaining it seems that in the Apple SDK for the Retina Display there's a bug and imageWithContentsOfFile actually does not automatically load the 2x images. I've stumbled into a nice post how to make a function which detects…
Marin Todorov
  • 6,377
  • 9
  • 45
  • 73
9
votes
1 answer

Loading NSImage with imageNamed from xcassets crash in older osx versions

So, I have an xcassets that is shared amongst quite a few apps. I'm developing with Xcode8 in a Mac Mini with MacOs Sierra installed in it. If I compile and run in the development machine, there's no issue at all. However, when I try to run it in a…
leandrodemarco
  • 1,552
  • 1
  • 15
  • 22
7
votes
2 answers

UIImage:imageWithContentsOfFile is 10 times slower in iOS 5.0

After simply recompiling our iPhone application on newly released iOS 5.0 SDK i faced strange problem - all UIImage:imageNamed (first call with actual image loading) and UIImage:imageWithContentsOfFile started to work 10 times slower than before. i…
IPv6
  • 405
  • 4
  • 17
7
votes
1 answer

(iphone) imageNamed when there are multiple files with same name?

as question says, How does imageNamed work when there are multiple files with the given name under the resource directory? Is there a way to differentiate two different files with same name (but different path)? Thank you
eugene
  • 39,839
  • 68
  • 255
  • 489
5
votes
6 answers

Use external image in UIImage imageNamed

I am downloading two images from the web Apple.png and Apple@2x.png. I want to use [UIImage imageNamed:@"Apple.png"] so it can use the build in features to detect whether it should display either Apple.png or Apple@2x.png. Now where do I store these…
Mark
  • 16,906
  • 20
  • 84
  • 117
5
votes
2 answers

iPhone App crashes after switching, possibly due to UIImage imageNamed

My app moves 10 UIImageViews randomly around the screen, and once an UIImageView hits the corner, it changes its image. The problem is: after switching between apps and going back to mine, the app crashes. The console gives me this message: "App"…
NoobDev4iPhone
  • 5,531
  • 10
  • 33
  • 33
5
votes
2 answers

UIImage "imageNamed:" works on iOS 8, but not 7?

There are several answers on SO already about "imageNamed:" not working, but none have included my particular wrinkle: I'm getting nil from "imageNamed:" on iOS 7, but the same build works on iOS 8. Obviously, everything is hooked up properly…
Nerrolken
  • 1,975
  • 3
  • 24
  • 53
3
votes
1 answer

NSImage imageNamed: for Mac Mini returns small icon instead of high-res

When using NSImage's imageNamed: method to get the icon for the current computer, if I'm running on a Mac Mini, then I get a low resolution image. If I run the same code from my MacBook, then I get a high-res icon like I'd expect. My code is as…
adam.wulf
  • 2,149
  • 20
  • 27
3
votes
2 answers

Retina support imageNamed @2x not working

Possible Duplicate: iOS 5.1 with Xcode 4.2 and retina in iPad 3 I am trying to make my app load on iPad 2 (since its running great on iPad 3). I have downscaled the images and now have 2 sets of images like: image.png and image@2x.png. When I try…
madmax21
  • 33
  • 1
  • 5
2
votes
2 answers

SpriteNode position versus touch location

So i'm using a spritenode with an image and I don't set the position of it. Funny enough I was having issues setting the position of it so I didn't and it by default was set to center of page (for obvious reason) which ended up being perfect. So now…
insta catering
  • 151
  • 2
  • 12
1
2 3 4