Moshe Moshe - 1 year ago 60
Objective-C Question

Where should I install my auto layout constraints in a UIView subclass?

I'm subclassing

to build a custom control. Where do I want to add my layout constraints on subviews?

I've added them in init, but I don't think that's the appropriate place to do anything beyond initialization. I don't want to do in
because I'm concerned about subsequent calls recreating the constraints.

What's the right place for this kind of thing?

Answer Source

There are lots of options here. I think both initWithFrame: and layoutSubviews (with appropriate checks to avoid double-adding) could work, but updateConstraints is the canonical place to install constraints on subviews. You'd also need to avoid double-adding there.