iOS给一个view添加虚线边框

- (void)addDottedLineFromImageView:(UIView *)bView {

    bView.layer.cornerRadius = 4;

    CAShapeLayer*borderLayer =  [[CAShapeLayeralloc]init];

    borderLayer.bounds= bView.bounds;

    borderLayer.position=CGPointMake(bView.centerX, bView.centerY);

    borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0, 68, 68) cornerRadius:4].CGPath;

    borderLayer.lineWidth=1;

    //虚线边框---小边框的长度

    borderLayer.lineDashPattern = @[@6,@4]; //前边是虚线的长度,后边是虚线之间空隙的长度

    borderLayer.lineDashPhase=0.1;

    borderLayer.fillColor=UIColor.clearColor.CGColor;

    borderLayer.strokeColor=BSHexColor(0xA6A8AB).CGColor;

    [bView.layeraddSublayer:borderLayer];

}


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容