UIScrollView -> UIView ->UIImageView
Posted
by RapidM
on Stack Overflow
See other posts from Stack Overflow
or by RapidM
Published on 2010-05-31T14:18:40Z
Indexed on
2010/05/31
14:22 UTC
Read the original article
Hit count: 179
Hi everyone,
I am trying to create a horizontal UIScrollView with a few images in it. The user should be able to scroll horizontal between all the images. If he holds down the finger the scrolling should stop.
I though about making a
- UIScrollView (320 x 122 px)
- UIView for the content + really big width
- UIImageView for the individual images
Here is my code:
headScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 122)];
[self.view addSubview:headScrollView];
// Dafür einen contentView programmatisch festlegen
headContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, headScrollView.frame.size.height)];
[headContentView setBackgroundColor:[UIColor lightGrayColor]];
[headScrollView addSubview:headContentView];
[headScrollView setContentSize:headContentView.frame.size];
headImageView = [[UIImageView alloc] init];
NSMutableArray *elements = [appDelegate getElements];
for (int i = 0; i < [elements count]; i++) {
headImageView.image = [UIImage imageNamed:[[elements objectAtIndex:i] nameOfElement]];
[headContentView addSubview:headImageView];
}
But it's not working. There is no image there :-( When I do a NSLOG i get 3 names of the images, so it should work...
Any ideas?
Thanks!
© Stack Overflow or respective owner