UITableViewCell show white background and cannot be modified on iOS7

后端 未结 14 1339
轻奢々
轻奢々 2020-11-28 18:42

I\'ve implemented a custom table view cell class that inherit from UITableViewCell. The tableview contains a background image, so I want cell\'s background to b

14条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 18:49

    You can also use colour code in order to make your UITableView Cell lucrative.

    [cell setBackgroundColor:[self colorWithHexString:@"1fbbff"]];
    

    This is the code for applying colour code method:

    -(UIColor*)colorWithHexString:(NSString*)hex
    {
        NSString *cString = [[hex stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    
        if ([cString length] < 6) return [UIColor grayColor];
    
        if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
    
        if ([cString length] != 6) return  [UIColor grayColor];
    
        NSRange range;
        range.location = 0;
        range.length = 2;
        NSString *rString = [cString substringWithRange:range];
    
        range.location = 2;
        NSString *gString = [cString substringWithRange:range];
    
        range.location = 4;
        NSString *bString = [cString substringWithRange:range];
    
        unsigned int r, g, b;
        [[NSScanner scannerWithString:rString] scanHexInt:&r];
        [[NSScanner scannerWithString:gString] scanHexInt:&g];
        [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
        return [UIColor colorWithRed:((float) r / 255.0f)
                             green:((float) g / 255.0f)
                              blue:((float) b / 255.0f)
                             alpha:1.0f];
    }
    

提交回复
热议问题