Posted By

Leech on 09/17/08


Tagged

cocoa ui xcode Objective-c iphone


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

DASKAjA


Default Displaying an image from the web or the application bundle


 / Published in: Objective C
 

URL: http://idevkit.com/forums/tutorials-code-samples-sdk/62-displaying-image-web-application-bundle.html#post132

  1. First a UIImage needs to be made, to make one with an image from the application bundle use this code:
  2.  
  3. UIImage *myImage = [ UIImage imageNamed: @"myImage.png" ];
  4.  
  5.  
  6. If you need to make an image from a URL you can do something like this:
  7. More info can be found about this technique here: http://idevkit.com/forums/tutorials-code-samples-sdk/3-one-line-uiimage-url.html
  8.  
  9. UIImage *myImage = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://img.youtube.com/vi/OhOahwZCO1s/2.jpg"]]];
  10.  
  11.  
  12. Now that the UIImage has been made it needs to be put into a UIImageView. This is simply done with the -initWithImage: method:
  13.  
  14. UIImageView *myImageView = [ [ UIImageView alloc ] initWithImage: myImage ];
  15.  
  16.  
  17. You can then add the image view as a subview to any other view. You can also change the frame to resize the image.

Report this snippet  

You need to login to post a comment.