Draw dotted border bottom for UITableViewCell

ios, uitableview

Solution

If it's the stroke that's too wide, try changing your layer's `lineWidth`. Something like this will do the trick:

border.lineWidth = 1. / [[UIScreen mainScreen] scale];

That'll draw a 1px line on non-Retina devices, and a 1px line (0.5pt) on Retina ones, resulting in an ultra-crisp line.

Also, you could build your path with just a single line instead of a rect using `moveToPoint` and `addLineToPoint` on a `UIBezierPath`:

UIBezierPath *bPath = [UIBezierPath new];
[bPath moveToPoint:CGPointZero];
[bPath addLineToPoint:(CGPoint){100, 0}];
border.path = bPath.CGPath;

Adjust as needed.

Problem

I would like add an dotted bottom border to my `UITableViewCell`. Currently, I am using the following code, ``` CAShapeLayer *border = [CAShapeLayer layer]; border.strokeColor = [UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor; border.fillColor = nil; border.lineDashPattern = @[@1, @1]; border.path = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath; border.frame = CGRectMake(cell.bounds.origin.x, cell.bounds.origin.y + cell.bounds.size.height, cell.bounds.size.width, 1); [cell.layer addSublayer:border]; ``` With this code I have a dotted border bottom for my cell but the height of the dotted border is two time too big. But I'm not very good to manipulate `CAShapeLayer` and I didn't find anything to help me. Thanks !

Original source

Related problems