ios - How to set a constraint using percentage? -


just direct question, had spent many hours trying find working solution faild.

in xcode, storyboard, how set constraint 1 view can located 30% of total window height top of superview? , need way supported ios devices of orientations.

please see illustration attached.enter image description here

thank help!!

update

sorry, have misunderstood problem.

you'll need add constraints code (the xconstraint totally arbitrary, must need define x, y positions, width , height, unambiguous layout):

@iboutlet weak var imageview: uiimageview!      override func viewdidlayoutsubviews() {         super.viewdidlayoutsubviews()          let yconstraint = nslayoutconstraint(item: imageview, attribute: .top, relatedby: .equal, toitem: view, attribute: .top, multiplier: 1, constant: view.bounds.height / 3)          let xconstraint = nslayoutconstraint(item: imageview, attribute: .leading, relatedby: .equal, toitem: view, attribute: .leading, multiplier: 1, constant: 30)          nslayoutconstraint.activateconstraints([yconstraint, xconstraint])     } 

this way, equation be:

imageview.top = 1 * view.top + (view.width / 3) 

original answer

auto layout uses following equation constraints:

aview.property = multiplier * bview.property + constant 

based on this, can add equal width/height constraint, add multiplier:

enter image description here

so equation be:

view.height = 0.3 * superview.height + 0 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - How can I echo out this array? -

javascript - IE11 incompatibility with jQuery's 'readonly'? -