2014-02-18 5 views
1

У меня есть UICollectionview с разделами и двумя классами ячеек.UICollectionViewCell изменить цвет фона

- (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.

ответ

0

Фикс путем обработки обеих ветвей корпуса (все случаи) при настройке, например:

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 метод.

Смежные вопросы