Change bottom border color of UITableViewCell

You can change easily and efficiently create custom borders for a custom UITableViewCell by overriding the drawRect method of the view.

For example:

@interface CustomCell: UITableViewCell

@end

@implementation CustomCell

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
    CGContextSetLineWidth(context, 0.5f);
    CGContextMoveToPoint(context, 0.0f, CGRectGetHeight(rect));
    CGContextAddLineToPoint(context, CGRectGetWidth(rect), CGRectGetHeight(rect));
    CGContextStrokePath(context);
}

// do some more customization

@end

The above code overrides the drawRect method and use the Core Drawing Library to create custom 0.5f width stroke line in the color blue.

This of course assumes that you've turned off the separator style for the corresponding table view

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;  
comments powered by Disqus