Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Last active September 13, 2015 04:53
Show Gist options
  • Save abbeyjackson/050b7b0a6692f3f166bb to your computer and use it in GitHub Desktop.
Save abbeyjackson/050b7b0a6692f3f166bb to your computer and use it in GitHub Desktop.
How to make a paged scrollview from images and text. Set up all outlets in addition to this. This is using objects for each "page" which contain two NSString properties and one UIImage property. Search: Announcement Slider, Image Slider, Paged Slider, Scrollview Slider, UIScrollview.
- (void)viewDidLoad {
[super viewDidLoad];
self.array = [self configureArray];
for (int i = 0; i < self.array.count; i++) {
CGRect frame;
frame.origin.x = self.view.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.view.frame.size;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
TestObject *object = [self.array objectAtIndex:i];
imageView.image = object.backgroundImage;
[self.scrollView addSubview:imageView];
UILabel *lineOne = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width - 20, 40)];
lineOne.text = object.lineOneText;
[imageView addSubview:lineOne];
UILabel *lineTwo = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, self.view.frame.size.width - 20, 40)];
lineTwo.text = object.lineTwoText;
[imageView addSubview:lineTwo];
}
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width*(self.array.count), self.view.frame.size.height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment