[英]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.