Button loop created, can't auto resize framing
===

I am having the hardest issue with autoresizing my pages with UIScrollview and button loop because the button loop is setting the fame programmatically.

Is there a way to set the button loop and to adjust button size automatically so it fits within Portrait/Landscape?

Code details:

I have created a UIScrollView, a UIView and a button loop. The UIScrollView is declared in the .h file and created in Interface Builder, the rest is programmed.

Here is my ViewController.m

    //scrollview settings
    scrollView.bounces=NO;
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.showsVerticalScrollIndicator=NO;
    scrollView.scrollsToTop = NO;
    
    buttons=[[NSMutableArray alloc]init];
   
    buttonNumber = 0;
    // How Many buttons to create: 100
    maxButtonNumber=100;
    // How many UIScrollView pages: 4
    Pages= 4;

    
    for (int i = 0; i < Pages; i++) {
        UIView *pageView = [[UIView alloc] init];
        pageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        int x = 0;
        for (int j = 0; j < 25; j++) {
            
            if (buttonNumber > maxButtonNumber) {
                break;
            } else {
                buttonNumber++; }
            int row = j / 5;
            if (j % 5 == 0) {
                x = 0; }
            
            //HERE IS MY BUTTON LOOP
             thumbIcon = [UIButton buttonWithType:UIButtonTypeRoundedRect];
             thumbIcon.tag = buttonNumber;

             // HERE is where I set it programmatically, but this whacks out Portrait Mode
             thumbIcon.frame = CGRectMake(x * (145 + 30) + 90, row * (85 + 20) + 55, 145, 85);
            
             [[thumbIcon layer] setBorderWidth:2.0f];
             [[thumbIcon layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
             [[thumbIcon layer] setCornerRadius:2.0f];
            
              thumbIconImage = [UIImage imageNamed:[NSString stringWithFormat:@"Image%d.jpg", buttonNumber]]; 
            //Add Images To Button
            [thumbIcon setImage:thumbIconImage forState:UIControlStateNormal];
            [thumbIcon addTarget:self action:@selector(gotoDetailView:)forControlEvents:UIControlEventTouchUpInside];
            [pageView addSubview:thumbIcon];
            [thumbIcon setEnabled:YES];
            [buttons addObject:thumbIcon];
            
            x++;
        }
        [pageView setFrame:CGRectMake(i * 768, 0, 1024, 704)];  
    [pageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
                [scrollView addSubview:pageView];
        [pageView release];
    }
        [scrollView setPagingEnabled:YES];
        [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * Pages, scrollView.frame.size.height)];  



I hope this code helps and you could shed some light on how one could resize automatically when creating loops that define framing.