如图所示,我通过 CGMake 创建了 52 周按钮:
这是我的周视图日历
这是我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
int rows = 13, columns = 4 ;
UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 80*columns, 32*rows)];
int currentTag = 0;
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor colorWithRed: 201.0/255.0 green: 201.0/255.0 blue:201.0/255.0 alpha: 1.0];
button.tag = currentTag;
currentTag++;
[button.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[button.layer setBorderWidth: 0.5];
if (x == 0 && y == 3) {
[button setBackgroundColor:[UIColor redColor]];
} else if(x == 1 && y == 5) {
[button setBackgroundColor:[UIColor redColor]];
} else if(x == 2 && y == 5) {
[button setBackgroundColor:[UIColor redColor]];
} else if(y == 0) {
[button setBackgroundColor:[UIColor greenColor]];
} else if(y == 1) {
[button setBackgroundColor:[UIColor greenColor]];
} else if(y == 2) {
[button setBackgroundColor:[UIColor greenColor]];
} else if(y == 3) {
[button setBackgroundColor:[UIColor greenColor]];
} else if(y == 4) {
[button setBackgroundColor:[UIColor greenColor]];
} else if(x == 1 && y == 6) {
[button setBackgroundColor:[UIColor blueColor]];
} else {
// [button setBackgroundColor:[UIColor grayColor]];
}
[button setTitle:[NSString stringWithFormat:@"W %d",currentTag] forState:UIControlStateNormal];
button.frame = CGRectMake(80*x, 32*y, 80, 32);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonView addSubview: button];
}
}
// Center the view which contains your buttons
CGPoint centerPoint = buttonView.center;
centerPoint.x = self.view.center.x;
buttonView.center = centerPoint;
[self.view addSubview:buttonView];
}
RightNow 我想在这个日历中有 12 个月,并为每 4 周添加 1 个月作为标题
我不知道如何使用 CGMake 创建此标头并将其放入我的循环中
你能帮帮我吗
提前致谢!