I'm just trying to create a UIImage View programmatically, I have a new view and I tried doing this
let imageName = "yourImage.png"
view.backgroundColor = UIColor.colorWithPatternImage(UIImage(named:imageName))
This code doesn't work. please help me as soon as possible
This is for image with 100 height and 100 width:
var imageViewObject :UIImageView
imageViewObject = UIImageView(frame:CGRectMake(0, 0, 100, 100));
imageViewObject.image = UIImage(named:"imageName.png")
self.view.addSubview(imageViewObject)
To resize the image to fit the view frame:
imageViewObject.contentMode = UIViewContentMode.ScaleToFill
or
imageViewObject.contentMode = UIViewContentMode.ScaleAspectFit
or
imageViewObject.contentMode = UIViewContentMode.ScaleAspectFill
First create UIImageView , add image in UIImageView with frame and than give image Name.The following code help you.
var imageView : UIImageView
imageView = UIImageView(frame:CGRectMake(10, 50, 100, 300));
imageView.image = UIImage(named:"image.jpg")
self.view.addSubview(imageView)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With