Last active
December 11, 2015 14:25
-
-
Save joelmarquez90/0364fb3b66ca127f23d3 to your computer and use it in GitHub Desktop.
ScrollView created programmatically with AutoLayout, using Masonry
This file contains 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
self.scrollView = [UIScrollView new]; | |
self.scrollView.pagingEnabled = YES; | |
self.scrollView.directionalLockEnabled = YES; | |
self.scrollView.showsHorizontalScrollIndicator = NO; | |
self.scrollView.showsVerticalScrollIndicator = NO; | |
self.contentView = [UIView new]; | |
[self.scrollView addSubview:self.contentView]; | |
[self.contentView updateConstraints:^(MASConstraintMaker *make) { | |
make.edges.equalTo(self.scrollView); | |
make.height.equalTo(self.scrollView); | |
}]; | |
UIView *lastElementView; | |
for (NSString *imageUrl in self.images) { | |
UIImageView *imageView = [UIImageView new]; | |
imageView.contentMode = UIViewContentModeScaleAspectFill; | |
imageView.clipsToBounds = YES; | |
[imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]]; | |
[self.contentView addSubview:imageView]; | |
[imageView updateConstraints:^(MASConstraintMaker *make) { | |
make.left.equalTo(lastElementView ? lastElementView.right : self.contentView.left); | |
make.top.equalTo(self.contentView); | |
make.height.equalTo(self.contentView); | |
make.width.equalTo(self.scrollView); | |
}]; | |
lastElementView = imageView; | |
} | |
[self.contentView updateConstraints:^(MASConstraintMaker *make) { | |
make.right.equalTo(lastElementView); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment