Create a UIImageView

suggest change

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:

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

Or set the frame after creating the view:

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents