id: 11776    nodeId: 11776    type: General    point: 85.0    linkPoint: 1.0    maker: cella    permission: linkable    made at: 2013.06.26 01:24    edited at: 2013.06.26 01:24
how to display an image on iOS

1. add images (ex. abc.png) to the project

Just drag an image file to the "project-folder/" or "project-folder/Supporting Files/" in Xcode.
Or mouse right button on "project-folder/Supporting Files/" > Add files to ... > select the image file.

2. in the view controller header file
@property (nonatomic,strong) IBOutlet UIImageView * imageView;

3. in the MainStoryBoard, add image view and connect this to the above IBOutlet.

4. in the view controller source file. The addSubview is necessary. At first I thought it is not required since the image view is already added to the view controller's view through the MainStoryBoard. When the image is selected in the MainStoryBoard's Attribute Inspector, this is right. But when the image file is selected by the program this "addSubview" is necessary.
UIImage * image = [UIImage imageNamed:@"Canada.png"];
self.imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:self.imageView];


Return to how to display an image on iOS