Dec 062011

UITableViewCell has a different background color under iOS4 and iOS5. I wanted to support iOS4 for my app and I need to change the cell’s background color on error and then change it back again. I couldn’t change it back again on both iOS4 and iOS5. Hence this hacky class method

+ (UIColor *)defaultBackgroundColor:(UITableViewCell *)inCell
    if (NULL == FFUtiltiesBackgroundCellColor) {
        // iOS 4 and iOS5 have different color backgrounds for tabbed group dialogs
        // hence this gross hack. Must put it in a utility class someday.
        // see
        //backgroundCellColor = usernameCell.contentView.backgroundColor;
        NSString *version = [[UIDevice currentDevice] systemVersion];
        NSString *firstLetter = [version substringToIndex:1]; 
        if (firstLetter == @"4") {
            FFUtiltiesBackgroundCellColor = [UIColor whiteColor];
        } else {
            FFUtiltiesBackgroundCellColor = [UIColor colorWithRed:(0xF7/255.0)green:(0xF7/255.0)  blue:(0xF7/255.0) alpha:1.0];

    return FFUtiltiesBackgroundCellColor;

Hey, it works. I don’t use this anymore, I no longer see a business case for support iOS4 for my apps. Then again, clients apps can make the case, so I’m certainly not deleting the code!

This has been incorporated into the open source EnkiUtils.