美文网首页
绘制虚线方法

绘制虚线方法

作者: 会飞的大西瓜v | 来源:发表于2017-04-01 10:09 被阅读15次

1.重写drawRect方法

- (void)drawRect:(CGRect)rect{
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    //设置虚线颜色
    CGContextSetStrokeColorWithColor(currentContext, [YSCUiUtils colorTwo].CGColor);
    //设置虚线宽度
    CGContextSetLineWidth(currentContext, 1);
    //设置虚线绘制起点
    CGContextMoveToPoint(currentContext, 0, 50);
    //设置虚线绘制终点
    CGContextAddLineToPoint(currentContext, SCREEN_WIDTH, 50);
    //设置虚线排列的宽度间隔:下面的arr中的数字表示先绘制3个点再绘制1个点
    CGFloat arr[] = {6,3};
    //下面最后一个参数“2”代表排列的个数。
    CGContextSetLineDash(currentContext, 0, arr, 4);
    CGContextDrawPath(currentContext, kCGPathStroke);
    
}

相关文章

网友评论

      本文标题:绘制虚线方法

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