[英]UICollectionViewCell change background color
我有带有部分和两个单元格类的UICollectionview
。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
myCell *cell;
firstDayInMonth = [self dayWeekStart:[self getDateFromItem:dateFromStart section:indexPath.section row:1]];
if (indexPath.row < firstDayInMonth) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellCalendarEmpty" forIndexPath:indexPath];
} else {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellCalendar" forIndexPath:indexPath];
}
}
我有开始项目,部分和期间。 从开始部分和项目开始,我需要根据时间段更改背景色单元。 我只需要更改cellCalendar
。 我使用cellCalendarEmpty
移动第一个cellCalendar
。
通过在配置时处理案例的两个分支(所有案例)来解决问题,例如:
if (indexPath.section == todayMonthSection && indexPath.item == dayPlusShift){
cell.backgroundColor = [UIColor colorWithRed:60.0/255.0 green:162.0/255.0 blue:161.0/255.0 alpha:1];
cell.titleLabel.textColor = [UIColor whiteColor];
} else {
cell.backgroundColor = [UIColor whiteColor]; // whatever the default color is
}
如果您使用的是UICollectionViewCell的自定义子类,则还可以通过实现prepareForReuse方法将其重置为默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.