gpt4 book ai didi

iphone - 在运行时自动调整 UIButton 的大小。

转载 作者:行者123 更新时间:2023-11-29 03:37:32 26 4
gpt4 key购买 nike

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

谢谢

最佳答案

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

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

关于iphone - 在运行时自动调整 UIButton 的大小。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18964160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com