Suhaib
Suhaib

Reputation: 2061

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() {
    super.viewDidLoad()

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

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

Upvotes: 0

Views: 217

Answers (1)

DevKyle
DevKyle

Reputation: 1091

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

override func viewDidLayoutSubviews() {



}

Upvotes: 1

Related Questions