【发布时间】:2014-09-08 06:44:28
【问题描述】:
我正在尝试根据 superView 的大小制作一个 UIButton Grid。我见过的大多数解决方案都是将按钮添加到 scrollView 。但是如果我不想要可滚动的网格而只是一个普通的网格怎么办.如何根据绘制按钮的超级视图的大小调整按钮的大小?。有人尝试过吗?非常感谢任何帮助。
-(void)createLayout{
int width =30;
int height =30;
int leftMargin =10;
int topMargin =10;
int xTile;
int yTile;
int xSpacing = 50;
int ySpacing = 50;
for (int c=1; c<=5; c++) {
for (int r=1; r<=10; r++) {
NSLog(@"row : %d col : %d",r,c);
yTile = ((c*ySpacing)+topMargin);
xTile = ((r*xSpacing)+leftMargin);
Test *btn = [Test buttonWithType:UIButtonTypeCustom];
btn.row = r;
btn.column =c;
[btn setTitle:[NSString stringWithFormat:@"%d,%d",btn.row,btn.column] forState:UIControlStateNormal ];
[btn.titleLabel setFont:[UIFont fontWithName:@"Arial" size:14]];
[btn setBackgroundColor:[UIColor redColor]];
[btn setFrame:CGRectMake(xTile, yTile, width, height)];
[self.scrollView addSubview:btn];
xTile=xTile+10;
}
yTile = yTile+10;
}
}
【问题讨论】:
-
将它们放在
layoutSubviews中。 -
你能详细解释一下吗:-]
标签: ios objective-c uiscrollview uibutton