Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you put a border around a UITableViewCell's contentView? (for testing)

what's the code to put a border around a UITableViewCell's contentView? (for testing)

If not possible why is this? (for my learning)

like image 779
Greg Avatar asked Oct 07 '11 02:10

Greg


3 Answers

Have you tried using contentView's underlying CALayer? Try something like this:

#import <QuartzCore/QuartzCore.h>

- (void)someAppropriateMethod
{
    [self.myTableViewCell.contentView.layer setBorderColor:[UIColor redColor].CGColor];
    [self.myTableViewCell.contentView.layer setBorderWidth:1.0f];
}
like image 176
Stuart Avatar answered Sep 18 '22 16:09

Stuart


You could also apply it to the cells contentView loke so:

#import <QuartzCore/QuartzCore.h>

- (void)someAppropriateMethod {
    myTableViewCell.contentView.layer.borderColor = [[UIColor redColor] CGColor];
    myTableViewCell.contentView.layer.borderWidth = 1;
}
like image 26
chown Avatar answered Sep 20 '22 16:09

chown


Swift 4:

myTableViewCell.contentView.layer.borderColor = UIColor.black.cgColor
myTableViewCell.contentView.layer.borderWidth = 1.0
like image 6
Ahmed Khedr Avatar answered Sep 18 '22 16:09

Ahmed Khedr