画虚线

作者: 林希品 | 来源:发表于2022-06-14 14:43 被阅读0次

//画虚线

  • (UIImage *)drawLineWithView:(UIImageView *)imageView lineColor:(UIColor *)lineColor {
    [imageView layoutIfNeeded];
    // 开始划线 划线的frame
    UIGraphicsBeginImageContext(imageView.frame.size);

    [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];

    // 获取上下文
    CGContextRef line = UIGraphicsGetCurrentContext();

    // 设置线条终点的形状
    CGContextSetLineCap(line, kCGLineCapRound);
    // 设置虚线的长度 和 间距
    CGFloat lengths[] = {3,3};

    CGContextSetStrokeColorWithColor(line, lineColor.CGColor);
    // 开始绘制虚线
    CGContextSetLineDash(line, 0, lengths, 2);

    CGContextMoveToPoint(line, 0.0, 2.0);

    CGContextAddLineToPoint(line, 300, 2.0);

    CGContextStrokePath(line);

    // UIGraphicsGetImageFromCurrentImageContext()返回的就是image
    return UIGraphicsGetImageFromCurrentImageContext();
    }

相关文章

  • 。虚线。?。画。?。懂吗。?。

    。把。该。用。虚线。?。画。?。的。用。虚线。?。画。?。懂吗。?。 。这是。清理。?。大脑。?。的。重点。?。懂...

  • 画虚线

    绘制一条水平的虚线

  • 画虚线

  • 画虚线

    - (void)drawLine { UIView*lineView = [[UIViewalloc]init];...

  • 画虚线

    注意事项: android:layerType="software"

  • 画虚线

    毕业之后才发现,数学都还给数学老师了。就连三角函数都忘了。请教大佬手把手教我老半天终于会画虚线了!做一下笔记,说不...

  • 画虚线

    //画虚线 (UIImage *)drawLineWithView:(UIImageView *)imageVie...

  • iOS竖直虚线画法

    项目中有画水平虚线和竖直虚线的需求,便在网上参考了别人的水平虚线画法,子类化了竖直虚线的DashLineView ...

  • 使用css3的repeating-linear-gradient

    还在用 border-style: dashed 画虚线吗?虽然也是虚线,但是不能控制每一个虚线的宽度

  • iOS绘图------虚线的画法

    在项目中, 有两个地方用到了画虚线 虚线标注某个点 虚线画按钮边框 两种方法不同, 第一个是用贝塞尔曲线来画, 第...

网友评论

    本文标题:画虚线

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