Last active
October 7, 2016 08:49
-
-
Save AdityaDeshmane/9adab850665c33b3b04e to your computer and use it in GitHub Desktop.
iOS : Subview Leading, Trailing, Top, Bottom Margin Constraint Visual format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Objective C | |
[self.view addSubview:_viewControllerToAdd.view]; | |
_viewControllerToAdd.view.translatesAutoresizingMaskIntoConstraints = NO; | |
UIView *subview = _viewControllerToAdd.view; | |
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[subview]-0-|" | |
options:0 | |
metrics:nil | |
views:NSDictionaryOfVariableBindings(subview)]]; | |
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[subview]-0-|" | |
options:0 | |
metrics:nil | |
views:NSDictionaryOfVariableBindings(subview)]]; | |
//Swift | |
self.viewInWhichYouAreAddingSubview.addSubview(vcChildToAdd.view); | |
let subview:UIView = vcChildToAdd.view; | |
self.viewInWhichYouAreAddingSubview.translatesAutoresizingMaskIntoConstraints = false | |
self.vcChildToAdd.view.translatesAutoresizingMaskIntoConstraints = false | |
self.viewInWhichYouAreAddingSubview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[subview]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["subview": subview])) | |
self.viewInWhichYouAreAddingSubview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[subview]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["subview": subview])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment