52個の正方形やボタン(1ページに1年で52週分)のビューをグリッドで作成したいのですが、どのように並べたらよいか、どのように枠に収めればよいかわかりません。
(13 行と 4 列になります)、しかし、このコードを試してみると、algin ではありません: すべてのボタンをフレームの横に配置するフレームを作成する方法がわかりません..
これが私のコードです:
- (void)viewDidLoad
{
[super viewDidLoad];
int rows = 13, columns = 4;
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(58 * x, 31 * y, 58, 31);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: button];
}
}
}
-(void)buttonPressed:(UIButton *)button
{
NSLog(@"button %u -- frame: %@", button.tag, NSStringFromCGRect(button.frame));
}