我正在使用 MBCalendarKit 来自定义日历。我想在每个日历单元格中添加文本标签。如需参考,请从 github“ https://github.com/MosheBerman/MBCalendarKit ”下载示例代码。
编辑:
为了制作多个标签,我使用了 for 循环。怎么了?
NSMutableArray *dateButtons = [NSMutableArray array];
for (NSInteger i = 1; i <= 42; i++) {
DateButton *dateButton = [DateButton buttonWithType:UIButtonTypeCustom];
dateButton.calendar = self.calendar;
[dateButton addTarget:self action:@selector(_dateButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UILabel *travelTime = [[UILabel alloc] initWithFrame:CGRectMake(3, 23, 20, 20)];
travelTime.font=[travelTime.font fontWithSize:9];
[travelTime setTextColor:[UIColor blueColor]];
travelTime.text = @"9";
UILabel *workTime = [[UILabel alloc] initWithFrame:CGRectMake(30, 23, 20, 20)];
workTime.font=[workTime.font fontWithSize:9];
[workTime setTextColor:[UIColor orangeColor]];
workTime.text = @"9";
[dateButton addSubview:travelTime];
[dateButton addSubview:workTime];
[dateButtons addObject:dateButton];
}
self.dateButtons = dateButtons;