Thursday, July 23, 2009

Image Display

To display an image on iPhone / iPod application developed using XCode, but without using UI Builder; i.e. manually writing code to display image:

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 150.0f, 80.0f); //This will create rectangle object to place image with start & end positions
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:myImageRect];
[[myImageView setImage:[UIImage imageName:@"myPhotoImage.png"]]; //Specify the name of image file with path
myImageView.opaque = YES; //Set the properties for image -- opaque,
[self.view addsubView:myImageView]; //Display the image
[myImageView release]; //Release the image object from memory

The above example is for showing image in rectangle, we can also show image in circle shape or any other custom shape.

-Mitesh Mehta
miteshvmehta@gmail.com

No comments:

Post a Comment