UICollectionView show strange when cell has background colro

Discussion in 'iOS Programming' started by mikezang, Nov 8, 2012.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I just create a UICollectionView, but when I set cell color, I got a strange result, can you tell me why?
    Code:
    - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
    {
        static NSString *kCellID = @"Cell";
        WordCell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
        
        cell.label.text = [NSString stringWithFormat:@"%i%i", indexPath.section, indexPath.row];
    
       switch (indexPath.row) {
            case 0:
            case 1:
            case 4:
            case 5:
                cell.backgroundColor = [UIColor greenColor];
                break;
                
            case 2:
            case 3:
            case 6:
                cell.backgroundColor = [UIColor redColor];
                break;
    
            default:
                break;
        }
        
        return cell;
    }
    
     

    Attached Files:

  2. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #2
    What's the issue here exactly? The fuzzy text?

    If so, try setting cell.label.backgroundColor also.
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    The line of red color is not on the same position with line of black cell, can you view?
     
  4. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #4
    Well, I can see that the whole table is moved upwards by 1-2 pixels. I presumed that's just because of the way you have taken the screenshot? I can't see anything in the code you have posted that would cause the position of the UICollectionView to change.
     

Share This Page