Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change imageview height programmatically ios

Tags:

ios

swift

iphone

I have this kind of structure in storyboard:

UIViewController > View > Scrollview > Scrollview > UIImageview

By Default imageview size is : 320x230. Check below image:

enter image description here

Now i need to change size of that imageview Programmatically.

Lets say i need to set frame : 320x280

Autolayout is disabled see image:

enter image description here

Here is what i have done:

override func viewDidLayoutSubviews(){
    super.viewDidLayoutSubviews()
    imgThumbnail.frame = (frame: CGRectMake(0, 0, self.result.width, 280))
}

But its not working at all. Its not changing size of imageview. One more important thing is when i scroll down & up the scrollview. It takes the new frame which i have set in above code in imageview.

It will be great if someone guide me resolve this issue.

Thanks in advance.

like image 704
Mayur Avatar asked Apr 08 '26 08:04

Mayur


1 Answers

Set imageView Autoresizing Property to None and height to required height as follows:-

imageView.autoresizingMask = .None
imageView.frame.size.height = 280.0

To better understand Autoresizing Masks refer this link :- Autoresizing masks programmatically vs Interface Builder / xib / nib

like image 151
Meet Avatar answered Apr 10 '26 22:04

Meet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!