iOS 画一条虚线

作者: 烟影很美 | 来源:发表于2016-02-17 10:47 被阅读661次

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];

    shapeLayer.position = CGPointMake(1, 2);

    shapeLayer.fillColor = nil;

    // 设置虚线颜色

    shapeLayer.strokeColor = HEXCOLOR(0xcccccc).CGColor;

    // 3.0f设置虚线的宽度

    shapeLayer.lineWidth = 2.0f;

    shapeLayer.lineJoin = kCALineJoinRound;

    // 2=线的宽度 3=每条线的间距

    shapeLayer.lineDashPattern = @[@2, @3];

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, NULL, 0, 0);

    CGPathAddLineToPoint(path, NULL, _allview.width,0);

    shapeLayer.path = path;

    CGPathRelease(path);

    [_allview.layer addSublayer:shapeLayer];

    参考:http://www.jianshu.com/p/265b9f6fb5f2

    http://www.cocoachina.com/ios/20150417/11610.html

    相关文章

      网友评论

      • 超_iOS:为什么我画的线会跑出这两句话的限制,终点越界啊
        CGPathMoveToPoint(path, NULL, 0, 0);

        CGPathAddLineToPoint(path, NULL, _allview.width,0);
        超_iOS:@小菜超 怀疑是这个view.的frame有关,不解
        烟影很美:@小菜超 _allview.width表示一个view的宽, 所以这条线的位置就是 (0,0)-(view的宽,0), 怎么会超出来呢, 我这里很正常
        超_iOS:@小菜超 求解惑,急

      本文标题:iOS 画一条虚线

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