Hey for some reason I am struggling with trying to set the height and width of one of my image views. I want to set it so the height only goes for 20% of my screen. I know to regularly set it you can do things like: image = (0,0,50,50)
But I need the height to not be a static number. Something like image = (0,0, frame.height * 0.2, 50)
Any suggestions?
The simplest way is to set the frame of your UIImageView and set the contentMode to one of the resizing options. I would NOT retain the result here. newImage will be autoreleased already, and it should up to the method that called this to retain it or not.
Step 1 : Click the Attribute Inspector, Select the Border Styles which is not the rounded one. Step 2 : Now go to Size Inspector and change the size of the TextField. Step 3 : Create an @IBOutlet for TextField and then add below code inside the viewWillAppear() or viewDidAppear() .
To maintain aspect ratio I calculated the width of UIImageView = (320/460)*450 = 313.043 dynamically. And set the contentMode For UIImageView is UIViewContentModeScaleAspectFit. And set the image(320x460) to image view but it is some what blur.
The accepted answer in Swift 3:
let screenSize: CGRect = UIScreen.main.bounds image.frame = CGRect(x: 0, y: 0, width: 50, height: screenSize.height * 0.2)
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