Draw the bottom border of the bottom border for a UITableViewCell

I would like to add a dotted bottom border to mine UITableViewCell.

I am currently 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 bottom border for my cell, but the height of the dotted border is twice too high.

But I did not manipulate very well CAShapeLayer, and I did not find anything to help me.

Thanks!

+4
source share
2 answers

If it is too wide, try changing the layer lineWidth. Something like this will do the trick:

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

This will draw a 1px line on devices other than Retina, and a 1px line (0.5pt) on Retina, which will lead to an ultramodern line.

, moveToPoint addLineToPoint UIBezierPath:

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

.

+4

/* drow line bottom */
cell.layer.shadowColor = [UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor;
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 0;
cell.layer.shadowOffset = CGSizeMake(0.0, 1.0);

..

, UITableView,

0

Source: https://habr.com/ru/post/1527516/


All Articles