0

I want to resize the existing UIButtons when i add a button at run time, just like safari iPad adds the tabs and all the tabs get resized when new tab get added. and i want to do it either using aotolayout or autoresizingmask.

Thanks

4

1 回答 1

1

创建一个可变集合以保留对按钮的引用。如果您需要以某种方式对它们进行排序,请创建 NSMutableArray,如果不需要,请创建 NSMutableSet。在头文件中声明像 NSMutableSet 按钮集一样的 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];
}

这应该做你正在寻找的。

于 2013-09-23T16:46:13.950 回答