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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -