Skip to content

Instantly share code, notes, and snippets.

@joelmarquez90
Last active December 11, 2015 14:25
Show Gist options
  • Save joelmarquez90/0364fb3b66ca127f23d3 to your computer and use it in GitHub Desktop.
Save joelmarquez90/0364fb3b66ca127f23d3 to your computer and use it in GitHub Desktop.
ScrollView created programmatically with AutoLayout, using Masonry
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