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
1
vote
1 answer

Using iOS filename Device Modifiers (~ipad, ~iphone) in Documents or Caches folder

Is there a way to take advantage of the device modifiers ~ipad, ~iphone, @2x, for images stored in the cache or documents. As far as I can tell it only works if the files are stored in the main bundle. NSArray *cachePaths =…
Nate Potter
  • 3,222
  • 2
  • 22
  • 24
1
vote
2 answers

Frame with 50 png in iPhone

I have a ViewController with 16 buttons. Each button loads a popover that show 50 frames renders in moving. What is the best form to do it? I know that imageWithName is bad because it load all images in cache, and for this reason im doing it…
Alberto Juarez
  • 444
  • 8
  • 23
0
votes
1 answer

UIImage that won't disappear when removing it from its superview

Under iOS 5, I encounter the following problem : the following code is called on a controller everytime a new product is picked in the application. It displays a bullet list of features in the controller's view. Every bullet is an image that is…
madewulf
  • 1,870
  • 4
  • 26
  • 41
0
votes
3 answers

mem allocation with imageNamed

I want to display some images, when image is not available I want to show a default one. When using the analyze functionality I get warnings about a potential leak. I do under stand that when using imageNamed there is no memory allocated, what would…
ErikS
  • 31
  • 1
  • 5
0
votes
1 answer

Adding PNG to UIImageView with code looks terrible compared to adding it directly in the NIB

How do I get the image added to the UIImageView to look the same when added in code as when I add it directly in the NIB? I have a 5 of clubs picture, in the NIB file I use the Image drop down to select the 5 of clubs picture from the resources. …
Johnne
  • 143
  • 10
0
votes
1 answer

How to give a name to a saved Image from the imagePickerController

I'm using an imagePickerController to replace my existing images inside my view. The function works within the same IB-file. However I'd like to load the chosen image in another IB-File as well. I think that the solution is to give a name to the…
BarryK88
  • 1,806
  • 2
  • 25
  • 41
0
votes
2 answers

How to assign unique names to images?

I'm writing a web application where users can upload images. I wonder what's the best practice of assigning unique names to images ? I thought MD5 can ben useful and enough, but since each image has an owner, do I have to use MD5 ? I mean it could…
iva123
  • 3,395
  • 10
  • 47
  • 68
0
votes
0 answers

How can you add a gif as a imageNamed item in swift?

I am attempting to swap a character in a game that does not move to a gif image that does move. Currently, the code is let player = Witch(imageNamed: "player") When I attempt to change the image to the gif by changing names, as expected, it…
Amber
  • 5
  • 2
0
votes
1 answer

UIImage ImageNamed method

In my app, I am loading several images onto a UIScrollView and I highlight a portion of the scroll view using Core Graphics routine. I have used the CGImageRelease and CGContextRelease to manage the memory during the routines. When I run the app…
DKV
  • 303
  • 1
  • 3
  • 4
0
votes
1 answer

Problems with images on iPhone

In my application I use lots of images based in interface builder. The problem with this is that it uses large amounts of memory because interface builder caches it much liked "imageNamed" so I've begun removing the image from imageViews in…
Jeff
  • 2,017
  • 3
  • 15
  • 8
0
votes
0 answers

sprite kit: imageNamed: or texture:?

I am currently working on a simple 2d sprite kit game. When I created the background "image" object I initialized it using the SKSpriteNode convenience imageNamed: initializer. However, after looking through some of the spriteKit documentation I…
Schanz97
  • 23
  • 3
0
votes
2 answers

iPhone app memory leak with UIImage animation? Problem testing on device

I have an animation which works fine in the simulator but crashes on the device. I am getting the following error... Program received signal: “0”. The Debugger has exited due to signal 10 (SIGBUS) A bit of investigating suggests that the UIImages…
user157733
  • 569
  • 2
  • 12
  • 26
0
votes
3 answers

How to RANDOMLY show many images on a single UIImage

So the BELOW code shows animation of all those colors in the order that I placed it. However, how would I make it that the colors appear in no particular order but instead appear in RANDOM order? bird.animationImages=[NSArray arrayWithObjects: …
Jet
  • 555
  • 1
  • 7
  • 19
0
votes
1 answer

how can i return same object in CGRectIntersectsRect if statement?

This line of code was working prior to iOS 8, but after updating to iOS 8 this line of code does not work anymore. if (CGRectIntersectsRect(icon1.frame, pig.frame) && icon1.image == [UIImage imageNamed:@"BerryBlueberryIphone.png"]) { what…
meno
  • 21
  • 3
0
votes
0 answers

is there reasons why this code won't work on iphone and will on ipad?

the code is: if(CGRectIntersectsRect(icon1.frame, pig.frame) && icon1.image == [UIImage imageNamed:@"BerryBlueberryIphone.png"]){ } the code works in ipad but not iphone. spelling is correct for png file i can't seem to find out why it does…