0

我在朋友的帮助下设置了一个滚动视图,一个循环在 4 个页面上添加 25 个按钮,最多 100 个按钮(实际上只是照片缩略图滑块的图像或缩略图)。

横有5个,下有5个;但是,它是为横向编程的,并且不知道正确的代码来纠正此问题,以便自动将按钮/缩略图调整为较小的大小或缩小以获取纵向视图。

由于我无法上下更改按钮(如 4 个和 6 个),我想我只会更改按钮大小以缩小它,但我不知道这是如何完成的。

我已经在 ViewController.h 中声明了 UIScrollView *scrollView 和 ints

    int buttonNumber;
    int maxButtonNumber;
    int Pages;
    IBOutlet UIScrollView *scrollView;
    NSString *detailImageString;

    IBOutlet UINavigationBar *topBar;
    IBOutlet UIPageControl *pageControl;
}

@property (nonatomic,retain) NSMutableArray *buttons;
@property (nonatomic,retain) UIButton*thumbIcon;
@property (nonatomic,retain) UIImage *thumbIconImage;
@property (nonatomic, retain) UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UINavigationBar *topBar;
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
@property (strong, nonatomic) DetailViewController *detailViewController;

这是 ViewController.m

    scrollView.bounces=NO;
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.showsVerticalScrollIndicator=NO;

    buttons=[[NSMutableArray alloc]init];

    static const CGFloat ButtonWidth = 145;
    static const CGFloat ButtonHeight = 85;

   scrollView.frame = CGRectMake(0, 0, 1024, 768);

    buttonNumber = 0;
    maxButtonNumber=100;

            Pages=4; 


    for (int i = 0; i < Pages; i++) {
        UIView *pageView = [[UIView alloc] initWithFrame:self.view.bounds];
        pageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;


        int x = 0;
        for (int j = 0; j < 25; j++) {
            if (buttonNumber > maxButtonNumber) {
                break;
            }
            buttonNumber++;
            //Create 5 Rows
            int row = j / 5;
            if (j % 5 == 0) {
                x = 0;
            }
            thumbIcon = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            thumbIcon.tag = buttonNumber;
            [thumbIcon setFrame:CGRectMake(x * (ButtonWidth + 30) + 90, row * (ButtonHeight + 20) + 75, ButtonWidth, ButtonHeight)];

            thumbIconImage = [UIImage imageNamed:[NSString stringWithFormat:@"Image%d.jpg", buttonNumber]]; 

            [thumbIcon setImage:thumbIconImage forState:UIControlStateNormal];

            [pageView addSubview:thumbIcon];
            [thumbIcon setEnabled:YES];
            [buttons addObject:thumbIcon];
            x++;
        }

       [pageView setFrame:CGRectMake(i * 1024, 0, 1024, 704)];

       [scrollView addSubview:pageView];

         [pageView release];

    }
    [scrollView setPagingEnabled:YES];
    [scrollView setContentSize:CGSizeMake(1024 * Pages, 704)];  

任何帮助,将不胜感激。谢谢!!

4

1 回答 1

0

您可以使用@property(nonatomic) UIViewAutoresizing autoresizingMask. UIView例如,如果您希望在旋转期间更改 UIButton 的宽度,您可以在初始化按钮后立即执行以下操作:

button.autoresizingMask = UIViewAutoresizingFlexibleWidth;

查看有关 autoresizingMask 的文档,看看它是否符合您的要求:http: //developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/ doc/uid/TP40006816-CH3-SW6

于 2012-07-19T03:20:34.633 回答