2014-02-18 4 views
1

나는 UICollectionview 섹션과 2 개의 셀 클래스가 있습니다.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을 바꿀 필요가있다. 먼저 cellCalendar으로 이동하려면 cellCalendarEmpty을 사용합니다. 경우의 두 가지 (모든 경우) 구성, 예를 처리하여

답변

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를 구현하여 기본값으로 재설정 할 수 있습니다 방법.