Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 运行时自动调整UIButton的大小。_Iphone_Ios_Ipad_Autoresizingmask_Autolayout - Fatal编程技术网

Iphone 运行时自动调整UIButton的大小。

Iphone 运行时自动调整UIButton的大小。,iphone,ios,ipad,autoresizingmask,autolayout,Iphone,Ios,Ipad,Autoresizingmask,Autolayout,我想在运行时添加按钮时调整现有UIButtons的大小,就像safari iPad添加选项卡一样,当添加新选项卡时,所有选项卡都会调整大小。我想用aotolayout或者autoresizingmask来实现 谢谢创建一个可变集合以保留对按钮的引用。如果您需要以某种方式对它们进行排序,请创建NSMutableArray,如果不需要,请创建NSMutableSet。在头文件中声明类似ivar的NSMutableSet按钮集,然后在类实现中: float x=0,y=0; buttonsSet =

我想在运行时添加按钮时调整现有UIButtons的大小,就像safari iPad添加选项卡一样,当添加新选项卡时,所有选项卡都会调整大小。我想用aotolayout或者autoresizingmask来实现


谢谢

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

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];
}

这应该符合你的要求

感谢阿披舍克的回答,但我正在寻找通过自动布局或自动调整大小面具来实现这一点的方法。无论如何,你的答案是+1。