【问题标题】:Auto resize UIButton at run time.在运行时自动调整 UIButton 的大小。
【发布时间】:2013-09-23 16:19:37
【问题描述】:

我想在运行时添加按钮时调整现有 UIButtons 的大小,就像 Safari iPad 添加选项卡并且在添加新选项卡时调整所有选项卡的大小一样。我想使用 aotolayout 或 autoresizingmask 来做到这一点。

谢谢

【问题讨论】:

    标签: iphone ios ipad autoresizingmask autolayout


    【解决方案1】:

    创建一个可变集合来保存对按钮的引用。如果您需要以某种方式对它们进行排序,请创建 NSMutableArray,如果不需要,请创建 NSMutableSet。在头文件中声明像NSMutableSetbuttonSet这样的ivar,然后在类实现中:

    float x=0,y=0;
    buttonsSet = [[NSMutableSet alloc] init];
    for( NSMutableDictionary *dict in places) {
        NSLog(@"x: %f",x);
        x=x+25;
        y=y+25;// Vary these depending on where you want the buttons to be
        UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(x,y,25,25)] autorelease];
        button.backgroundColor=[UIColor redColor];
        [buttonsSet addObject:button];
        [self addSubview:button];
    }
    

    这应该可以满足您的需求。

    【讨论】:

    • 感谢 abhishek 的回答,但我正在寻找通过自动布局或自动调整蒙版的方法。无论如何 +1 为您的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    相关资源
    最近更新 更多