Heuristic
Heuristic

Reputation: 5341

Any workaround to have different constraints for same size class?

Say I need to have a view which has leading and trailing spacings, on iPhone SE the spacings should be 16, on larger phones I can have 32 as spacing, however in portrait mode the horizontal size class is always Compact, which means I can't apply different spacings for different size classes.

Then I thought about having High priority constraints instead of Required, and make the intrinsic content size of the view to be, say, 288, so on iPhone SE, the spacings have to be 16 and 16 (ie. 16 + 288 + 16 = 32), but on larger phones it can be 32. Haven't tried this but can someone point me the correct direction of solving this problem?

Thanks!

Edit: The view is actually a UILabel, and I don't want to give it a hardcoded width constraint.

Upvotes: 2

Views: 123

Answers (1)

trapper
trapper

Reputation: 11993

I solve these issues more generally by using a constraint multiplier. It may not be exactly 16/32 but you can get a similar effect.

You can set hard limits like required min 16, required max 32 and then set another a lower priority constraint of parent width * someMultiplier

Upvotes: 1

Related Questions