Member-only story

Create a UIImageView iOS

Mr.Javed Multani
1 min readOct 5, 2020

--

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

//Swiftlet imageView = UIImageView()//Objective-CUIImageView *imageView = [[UIImageView alloc] init];

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

//SwiftimageView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)//Objective-CimageView.frame = CGRectMake(0,0,200,200);

Or you can set the size during initialization:

//SwiftUIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
//Objective-CUIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,200);//Alternative way of defining frame for UIImageViewUIImageView *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.

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet