iOS View新增虛線邊框
阿新 • • 發佈:2019-02-06
borderLayer.bounds設定為比view小一點,虛線比較明顯
borderLayer.lineDashPattern的屬性設定不同大小能修改虛線每一小段的長度
把cell.backView替換為對應的view就可以了
CAShapeLayer *borderLayer = [CAShapeLayer layer];
borderLayer.bounds = CGRectMake(1, 1, ScreenWidth-34, 48);borderLayer.position = CGPointMake(CGRectGetMidX(cell.backView.bounds), CGRectGetMidY(cell.backView.bounds));
borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:3].CGPath;
borderLayer.lineWidth = 1;
//虛線邊框
borderLayer.lineDashPattern = @[@4, @4];
//實線邊框
// borderLayer.lineDashPattern = nil;
borderLayer.fillColor = [UIColor clearColor].CGColor;
borderLayer.strokeColor = [UIColor grayColor].CGColor;
[cell.backView.layer addSublayer:borderLayer];