iOS 代码实现边框 虚线

 

//在初始化调用这个方法

func addshapeLayer(){

        shapeLayer = CAShapeLayer(layer:layer)

        borderLabel.layer.addSublayer(shapeLayer)

  }


//添加时候 调用这个方法

    

  func draswTopDsline(lineLab:UILabel,lineLength:CGFloat,lineSpaceing:CGFloat) {

        shapeLayer.bounds = lineLab.bounds

        shapeLayer.position = CGPointMake(CGRectGetWidth(lineLab.frame)/2,CGRectGetHeight(lineLab.frame)/2)

        shapeLayer.fillColor = UIColor.clearColor().CGColor

        shapeLayer.strokeColor = ColorValue.color_9.CGColor

        shapeLayer.lineWidth = 1.0

        shapeLayer.lineJoin = kCALineJoinRound

        let array:[NSNumber] = [lineLength,lineLength,0]

        shapeLayer.lineDashPattern = array

        

        //

        let path =  CGPathCreateMutable()

        CGPathMoveToPoint(path, nil, 0,0)

        CGPathAddLineToPoint(path, nil,CGRectGetWidth(lineLab.frame), 0)

        

        //

        CGPathMoveToPoint(path,nil , 0, CGRectGetHeight(lineLab.frame))

        CGPathAddLineToPoint(path, nil, CGRectGetWidth(lineLab.frame),CGRectGetHeight(lineLab.frame))

        

        //

        CGPathMoveToPoint(path, nil, 0, 0)

        CGPathAddLineToPoint(path, nil, 0, CGRectGetHeight(lineLab.frame))


        //

        CGPathMoveToPoint(path, nil, CGRectGetWidth(lineLab.frame), 0)

        CGPathAddLineToPoint(path, nil, CGRectGetWidth(lineLab.frame), CGRectGetHeight(lineLab.frame))

        

        shapeLayer.path = path

        

    }


你可能感兴趣的:(学习方法)