美文网首页
iOS view画圆角虚线

iOS view画圆角虚线

作者: 阿木小丸子 | 来源:发表于2018-03-27 19:25 被阅读0次

#pragma mark 虚线边框

- (void)addBorderToLayer:(UIView *)view

{

    CAShapeLayer *border = [CAShapeLayer layer];

    //  线条颜色

    border.strokeColor = [UIColor blackColor].CGColor;

    border.fillColor = nil;

//    border.path = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;

    border.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds cornerRadius:8].CGPath;

    border.frame = view.bounds;

    // 不要设太大 不然看不出效果

    border.lineWidth = 1;

    border.lineCap = @"square";

    //  第一个是 线条长度  第二个是间距    nil时为实线

    border.lineDashPattern = @[@6, @4];

    [view.layer addSublayer:border];

}

相关文章

网友评论

      本文标题:iOS view画圆角虚线

      本文链接:https://www.haomeiwen.com/subject/hbgscftx.html