Philip Philip - 7 months ago 17
Swift Question

swift change height of UIView

Turned off auto layout for the view. However this doesnt work. I have no restraints regarding height. Only width that equal parent views width.

@IBOutlet weak var questionTextView: UITextView!
override func viewDidLoad() {
var newFrame = CGRectMake(0, 0, 300, 202)
questionView.frame = newFrame
}

Answer

Did you turn off auto layout for the entire nib in interface builder?

You can't turn off auto layout for specific sub-views in interface builder - you can only do it at runtime programmatically.

Based on what you said you still have a constraint active. How do you have constraints when you've turned off auto layout already?

If you have auto layout active, setting the height for your view by using the frame won't work since it'll conflict with auto layout rules.

If you need to change the height of a view with auto layout active, you'll need to create an IBOutlet for your height constraint and modify that at runtime, i.e.:

@IBOutlet weak var heightConstraint: NSLayoutConstraint!

self.heightConstraint.constant = 200