I'm trying to position a view in storyboard to always have it top edge at 1/3 of screen size. I have currently set a constraint to Top Layout Guide, but the constraint's constant is...well it is constant no matter which screen size it is used in, but I want it to be 1/3 of screen size. Can this be done entirely in storyboard? Thanks for answers
Screenshot of current state:
You can add empty (clear color) UIView, pin it to the top, and set it's height to be equal to 1/3 of the superview. Then you can pin the top of your yellow view to the bottom of your empty UIView.
For anyone trying to make this work programatically I was not able to handle that by 'anchors' style but old NSLayoutConstraint
initializer worked:
let constraint = NSLayoutConstraint(item: floatingBtn,
attribute: .centerY,
relatedBy: .equal,
toItem: view,
attribute: .bottom,
multiplier: 1/3,
constant: 0)
constraint.isActive = true
Credits to accepted answer.
来源:https://stackoverflow.com/questions/32100248/position-a-view-in-storyboard-at-1-3-of-screen-size