jeff ayan
jeff ayan

Reputation: 849

How to add constraints to CALayer programatically

Do you have any idea about adding constraints to CALayer programmatically?

Upvotes: 0

Views: 1869

Answers (2)

LGP
LGP

Reputation: 4323

There are several ways to constraint a CALayer, although you cannot use NSLayoutConstraints. Most flexible way is to sub-class CALayer and override - (void)layoutSublayers;. Then you can position and size your content however you want. A simpler and more limited approach is to set the layer's contentsGravity property. With this you can set the layer to (for example) always position content in a corner, or do aspect fill.

Read more about contentsGravity.

Upvotes: 3

Ivan Kvyatkovskiy
Ivan Kvyatkovskiy

Reputation: 717

Constraints is a part of AutoLayout system of UIVIew, so no you cant do this

Upvotes: 0

Related Questions