Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change height of UIView with autolayout turned off

Turned off auto layout for the view. However this doesn't 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
}
like image 320
Philip Avatar asked Apr 27 '15 15:04

Philip


People also ask

How do I turn off Autolayout?

Disabling autolayout is a quick and easy process that can be completed in just a few seconds. Simply open your design in Figma, select the layer you want to disable autolayout for, and then click on the “None” option in the Layout section of the properties panel. That's all there is to it!

What are two properties that auto Layout constraints control on a UIView?

Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.

What is Autolayout aspect ratio?

If you select Aspect Ratio for a single item, the width of the item is used as the numerator for the ratio, and the height is used for the denominator. If you select Aspect Ratio for multiple items, Auto Layout chooses the width of one of the items for the numerator and the height of another item for the denominator.

How do I use Autolayout?

You can add auto layout to a selected frame, component, or component set from a few places: Use the keyboard shortcut ⇧ Shift A . In the right sidebar, click next to Auto layout with a frame selected. Right-click on a frame or object and select Add Auto layout.


1 Answers

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
like image 74
mmilo Avatar answered Sep 18 '22 06:09

mmilo