Objective-c – How to display a picture on UIView programmatically

objective cuiview

I want to ask a question about the UIview on the iPhone applicaiton. I want to display a image one the UIView programmatically, but I don't know how to do it. What should I do to display the image. Thank you very much.

Best Answer

You should use UIImageView. It is a subclass of UIView and you can set the image with an instance on UIImage.

Here is an example to add it to another UIView.

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nameofimage.png"]];
[myUIView addSubview:imageView];