Autolayout: origin and size should change according to width and height factor

前端 未结 5 1879
-上瘾入骨i
-上瘾入骨i 2020-12-10 04:12

Here is a scenario what I needed.

I have put a UIButton on IB (size iPhone4 inch) whose initial frame on IB is x:100,y:100,w:100,h:100. I want the o

5条回答
  •  生来不讨喜
    2020-12-10 04:33

    Use the multiplier of the constraints. So, set up a constraint that the button's width equals the top view's width with a multiplier of 100:320 (you can use this ratio form to express the multiplier). Set the constraint's constant to 0. Do the same for button's height proportional to top view's height (ratio 100:568). For the button's position, constrain the button's leading to the top view's width with a ratio of 100:320 and the button's top to the top view's height with a ratio of 100:568.

提交回复
热议问题