Looking for ios Answers? Try Ask4KnowledgeBase
Looking for ios Keywords? Try Ask4Keywords

iOS Create a UIImageView


To create a UIImageView programmatically, all you need to do is create an instance of UIImageView:

let imageView = UIImageView()

UIImageView *imageView = [[UIImageView alloc] init];

You can set the size and position of the UIImageView with a CGRect:

imageView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)

imageView.frame = CGRectMake(0,0,200,200);

Or you can set the size during initialization:

UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,200);

//Alternative way of defining frame for UIImageView
UIImageView *imageView = [[UIImageView alloc] init];
CGRect imageViewFrame = imageView.frame;
imageViewFrame.size.width = 200;
imageViewFrame.size.height = 200;
imageViewFrame.origin.x = 0;
imageViewFrame.origin.y = 0;
imageView.frame = imageViewFrame;

Note: You must import UIKit to use a UIImageView.