Last active
April 7, 2016 07:39
-
-
Save christianroman/11027662 to your computer and use it in GitHub Desktop.
UIScrollView + Auto Layout, no frames no contentSize
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
UIScrollView *scrollView = [UIScrollView new]; | |
scrollView.translatesAutoresizingMaskIntoConstraints = NO; | |
[self.view addSubview:scrollView]; | |
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" | |
options:0 | |
metrics:nil | |
views:@{@"scrollView" : scrollView}]]; | |
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" | |
options:0 | |
metrics:nil | |
views:@{@"scrollView" : scrollView}]]; | |
UIImageView *previousImageView = nil; | |
for (int i = 0; i < 10; i++) { | |
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]]; | |
imageView.translatesAutoresizingMaskIntoConstraints = NO; | |
[scrollView addSubview:imageView]; | |
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]" | |
options:0 | |
metrics:nil | |
views:@{@"imageView" : imageView}]]; | |
if (!previousImageView) { | |
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]" | |
options:0 | |
metrics:nil | |
views:@{@"imageView" : imageView}]]; | |
} else { | |
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[previousImageView][imageView]" | |
options:0 | |
metrics:nil | |
views:@{@"imageView" : imageView, | |
@"previousImageView" : previousImageView}]]; | |
} | |
previousImageView = imageView; | |
} | |
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[previousImageView]|" | |
options:0 | |
metrics:nil | |
views:@{@"previousImageView" : previousImageView}]]; | |
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[previousImageView]|" | |
options:0 | |
metrics:nil | |
views:@{@"previousImageView" : previousImageView}]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment