Suhaib Suhaib - 1 month ago 4x
Swift Question

How to programatically change the Width/Height of a UIImageView created via Interface Builder?

I created this UIImageView in Xcode and then added an image. See the picture below :

enter image description here

Then I added this code to try to change the UIImageView but its not working:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var border: UIImageView!

override func viewDidLoad() {

let width = UIScreen.mainScreen().bounds.width
let height = UIScreen.mainScreen().bounds.height

border.frame.size.width = width
border.frame.size.height = height


I believe you have to do this in ViewDidLayoutSubviews, not ViewDidLoad:

override func viewDidLayoutSubviews() {