I have two views: toastView and view. toastView is subview of view.
I want to position toastView on the y axis by 80% of view height.
How can I do this using constants in the code?
I assumed that there is a method like:
[toastView.topAnchor constraintEqualToAnchor:view.heightAnchor multiplier:0.8].active = YES;
but i can't mixing NSLayoutDimension (width and height) and NSLayoutYAxisAnchor (X and Y)
This is how it looks in the design:

The trick here is to set the top of toastView equal to the bottom of self.view with a multiplier of 0.8:
Objective-C:
[NSLayoutConstraint constraintWithItem: toastView attribute: NSLayoutAttributeTop
relatedBy: NSLayoutRelationEqual toItem: self.view
attribute: NSLayoutAttributeBottom multiplier: 0.8 constant: 0].active = YES;
Swift:
NSLayoutConstraint(item: toastView, attribute: .top, relatedBy: .equal,
toItem: self.view, attribute: .bottom, multiplier: 0.8, constant: 0).isActive = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With