Tricertops/KeepLayout

Shortcuts for constraints with multiplier value

a-voronov opened this issue · 2 comments

Hi and thank you for this nice and handy library!

My question is, if I can somehow easily set constraint multiplier value as simply as it is done with constants?
For example, having constraint like this, is it possible to convert it to KeepLayout?
Or there are different ways for constructing layouts like this?

[NSLayoutConstraint constraintWithItem:self
                             attribute:NSLayoutAttributeBottom
                             relatedBy:NSLayoutRelationEqual
                                toItem:self.submitRatingButton
                             attribute:NSLayoutAttributeBottom
                            multiplier:1.26
                              constant:0]

Thanks

KeepLayout supports a most common subset of Auto Layout and this exact case (align bottom with multiplier) is not supported directly.

However, it should be possible to simulate all the unsupported attribute combinations with some helper views. If I understood correctly what you want to achieve, I suggest you to try:

  1. Create helper view in the center of self.
  2. Make it’s height a multiple of self.
  3. Align the bottom of the rating button with the helper view.
UIView *helper = [UIView new];
[self addSubview:helper];
[helper keepCentered]; // Step 1
helper.keepHeightTo(self).equal = 0.48; // Step 2
self.submitRatingButton.keepBottomAlignTo(helper).equal = 0; // Step 3

Adjust the multiplier if I got it wrong (1 − 0.26 × 2 = 0.48).

intermediate helper view, of course, thank you!