iOS画虚线

来源:互联网 发布:mac唇膏试色最全 编辑:程序博客网 时间:2024/04/27 14:31

    //画虚线

    CAShapeLayer *shapeLayer = [CAShapeLayerlayer];

    shapeLayer.frame=CGRectMake(15,300,290,0.5);

    [shapeLayer setFillColor:[[UIColorclearColor]CGColor]];

    // 设置虚线颜色为blackColor

    [shapeLayer setStrokeColor:[UIColorblackColor].CGColor];

    //设置虚线的宽度

    [shapeLayer setLineWidth:shapeLayer.bounds.size.height];

    [shapeLayer setLineJoin:kCALineJoinRound];

    [shapeLayer setLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:2],nil]];  //.......1

    CGMutablePathRef path =CGPathCreateMutable();

    CGPathMoveToPoint(path,NULL,0,0);

    CGPathAddLineToPoint(path, NULL,shapeLayer.bounds.size.width,0);

    [shapeLayer setPath:path];

    CGPathRelease(path);

    [[self.viewlayer]addSublayer:shapeLayer];

效果如图:



改变第一行代码为:

 [shapeLayer setLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:3],[NSNumbernumberWithInt:5],[NSNumbernumberWithInt:20],[NSNumbernumberWithInt:5],nil]];

效果如图:


0 0
原创粉丝点击