Skip to content

Instantly share code, notes, and snippets.

@sebk
Forked from nandodelauni/UIScrollView+Images.m
Created January 27, 2014 13:44
Show Gist options
  • Save sebk/8648796 to your computer and use it in GitHub Desktop.
Save sebk/8648796 to your computer and use it in GitHub Desktop.
#import "UIScrollView+Images.h"
@implementation UIScrollView (Images)
- (void)addImages:(NSArray *)images
{
NSMutableDictionary *viewsDictionary = [NSMutableDictionary dictionary];
NSMutableString *visualFormatString = [NSMutableString stringWithString:@"|"];
NSUInteger index = 0;
for (UIImage *anImage in images) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:anImage];
[self addSubview:imageView];
imageView.translatesAutoresizingMaskIntoConstraints = NO;
NSString *key = [NSString stringWithFormat:@"imageView%d", index];
[visualFormatString appendFormat:@"[%@]", key];
[viewsDictionary setObject:imageView forKey:key];
index++;
}
[visualFormatString appendString:@"|"];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:visualFormatString options:0 metrics:nil views:viewsDictionary]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment