laying out images in UIScrollView automatically

Posted by Steve Jabs on Stack Overflow See other posts from Stack Overflow or by Steve Jabs
Published on 2011-06-27T02:50:56Z Indexed on 2011/06/27 8:22 UTC
Read the original article Hit count: 173

Filed under:
|
|
|
|

i have a list of images retrieved from xml i want to populate them to a uiscrollview in an order such that it will look like this.

1 2 3

4 5 6

7 8 9

10

if there is only 10 images it will just stop here.

right now my current code is this

for (int i = 3; i<[appDelegate.ZensaiALLitems count]-1; i++) {
        UIButton *zenbutton2 =[UIButton buttonWithType:UIButtonTypeCustom];
        Items *ZensaiPLUitems = [appDelegate.ZensaiALLitems objectAtIndex:i];
        NSURL *ZensaiimageSmallURL = [NSURL URLWithString:ZensaiPLUitems.ZensaiimageSmallURL];
        NSLog(@"FVGFVEFV :%@", ZensaiPLUitems.ZensaiimageSmallURL);
        NSData *simageData = [NSData dataWithContentsOfURL:ZensaiimageSmallURL];
        UIImage *itemSmallimage = [UIImage imageWithData:simageData];
        [zenbutton2 setImage:itemSmallimage forState:UIControlStateNormal];
        zenbutton2.frame=CGRectMake( (i*110+i*110)-660 , 300, 200, 250);
        [zenbutton2 addTarget:self action:@selector(ShowNextZensaiPage) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:zenbutton2];
}

notice the CGRectMake , i have to manually assign fixed values to position them. Is there any way to populate them out without manually assigning. for e.g the images will automatically go down a position once the first row has 3 images and subsequently for the rest.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode