AutoLayout to keep view sizes proportional

前端 未结 9 880
南笙
南笙 2020-12-04 23:53

I\'m trying to achieve the following:

  • I have 2 views in my xib that need to stay 20 pixels off the edge (both sides and top)
  • The 2 views that need to
9条回答
  •  粉色の甜心
    2020-12-05 00:19

    1. Remove the two width constraints in code, or lessen their priorities in IB, otherwise you are over-constrained.
    2. Add a constraint to describe the width ratio between the green view and blue view, in code:

      // Assuming the ratio you want is green_view_width : blue_view_width = 1 : 2
      NSLayoutConstraint *c = [NSLayoutConstraint constraintWithItem:greenView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeWidth multiplier:0.5f constant:0.f];
      [commonSuperview addConstraint:c];
      

提交回复
热议问题