NSLayoutXAxisAnchor [Horizontal]
Swift myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true Objective-C [self.myView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES; Top and Bottom Layout guides
// Swift myView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 8.0).isActive = true // Objective-C [self.stackView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor constant:8.0].active = YES; |
NSLayoutYAxisAnchor [Vertical]
Swift myView.bottomAnchor.constraint(equalTo: view.topAnchor, constant: 8).isActive = true Objective-C self.myView.bottomAnchor constraintEqualToAnchor:self.view.topAnchor constant:8.0].active = YES Example 2Example to make the height of a view twice the height of another view with a multiplier: // Swift myView.heightAnchor.constraint(equalTo: otherView.heightAnchor, multiplier: 2.0).isActive = true // Objective-C [self.myView.heightAnchor constraintEqualToAnchor:self.otherView.heightAnchor multiplier:2.0].active = YES |
NSLAyoutDimension [Size-Based Constrains]
// Swift myView.widthAnchor.constraint(equalToConstant: 50.0).isActive = true // Objective-C [self.myView.widthAnchor constraintEqualToConstant:50.0].active = YES; |
View Margins
// Swift let margins = view.layoutMarginsGuide myView.leadingAnchor.constraint(equalTo: margins.leadingAnchor).isActive = true // Objective-C UILayoutGuide *margins = self.view.layoutMarginsGuide; [self.myView.leadingAnchor constraintEqualToAnchor: margins.leadingAnchor].active = YES; |
Cheatography
https://cheatography.com
Autolayout Constrains Cheat Sheet by alr
Swift Autolayout Anchor Constrains
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets