Colas
Colas

Reputation: 3573

How can I change the size of an NSView when autolayout is active?

I have a NSViewController with an attached view defined in a xib. Everything is done properly (at least I hope), so that when I change the height of the view, all the subviews stay properly organized.

I want to change the height of the view programmatically. Basically, one of the subviews of my view is an NSTextView and when there is a lot of text inside, I want to enlarge the view.

If I change the frame.size of the view, nothing happens, because of the auto layout I think.

Is there a standard way to change the height (or the width) of the view in such a context ?


EDIT : I have added a constraint to the view : I "pined" its height. Then, I have added this constraint as an IBOutlet property. Thus, I can change the .constant value of the constraint.

Upvotes: 1

Views: 1800

Answers (1)

Colas
Colas

Reputation: 3573

  1. Create a new constraint for the view : "pin" its height.
  2. Register this constraint as an IBOutlet property.
  3. You can access the constraint and .constant value of it to change the size of your view.

Upvotes: 3

Related Questions