无法使UIButton autoresizingMask正常工作 [英] Cannot get UIButton autoresizingMask to work

查看:86
本文介绍了无法使UIButton autoresizingMask正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

- (void)loadView {
[super loadView];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 87, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 2;
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
scroll.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[self.view addSubview:scroll];
for (int i = 0; i < numberOfViews; i++) {
    CGFloat yOrigin = i * self.view.frame.size.width;
    UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [scroll addSubview:awesomeView];
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    int x=1;
    for (int i=0; i<=2; i++) {
        for (int z=0; z<=2; z++) {
            myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            myButton.frame = CGRectMake(4+(80*z), 122+(61*i), 72, 53);
            NSString *numero=[NSString stringWithFormat:@"%d", x];
            x++;
            [myButton setTitle:numero forState:UIControlStateNormal];
            myButton.titleLabel.font = [UIFont fontWithName:@"System Bold" size:31];
            myButton.titleLabel.font = [UIFont boldSystemFontOfSize:31];
            [myButton addTarget:self action:@selector(numeros:) forControlEvents:UIControlEventTouchUpInside];
            myButton.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
            [awesomeView addSubview:myButton];
        }
    }
}
}

创建一个ScrollView,并放置9个UIButton.

Which creates an ScrollView, and put 9 UIButton's.

我的问题是:当我以前使用IB放置UIButton时,这些按钮会自动自动调整大小并将其排列在iPad视图上,现在我得到了:

My problem is: when I used to use IB to put the UIButton, the buttons automatically autosized and arrange itselves on the iPad view, and now Im getting this:

有什么想法吗?谢谢. :D

Any ideas? Thanks. :D

推荐答案

awesomeView的autoresizesSubviews属性未设置为YES.我认为默认情况下是NO.

awesomeView does not have its autoresizesSubviews property set to YES. I think it's NO by default.

这篇关于无法使UIButton autoresizingMask正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆