美文网首页
iOS 画虚线

iOS 画虚线

作者: 旅途开发者 | 来源:发表于2017-01-06 10:50 被阅读111次

在所需要的view上画一条虚线,重写下面的方法即可

-(void)drawRect:(CGRect)rect{

[super drawRect:rect];

CGContextRef currentContext = UIGraphicsGetCurrentContext();

//设置虚线颜色

CGContextSetStrokeColorWithColor(currentContext, UIColorFromRGB(0x999999).CGColor);

//设置虚线宽度

CGContextSetLineWidth(currentContext, 1);

CGContextSetAlpha(currentContext, 1);

//设置虚线绘制起点

CGContextMoveToPoint(currentContext, 10, 49);

//设置虚线绘制终点

CGContextAddLineToPoint(currentContext, self.frame.origin.x + self.frame.size.width, 49);

//设置虚线排列的宽度间隔:下面的arr中的数字表示先绘制3个点再绘制1个点

CGFloat arr[] = {5,1};

//下面最后一个参数“2”代表排列的个数。

CGContextSetLineDash(currentContext, 0, arr, 2);

CGContextDrawPath(currentContext, kCGPathStroke);

}

相关文章

  • iOS 画虚线

    通过Quartz2D画虚线

  • iOS 画虚线

    创建一个UIView的子类,在drawRect:(CGRect)rect里

  • iOS 画虚线

    在所需要的view上画一条虚线,重写下面的方法即可 -(void)drawRect:(CGRect)rect{ [...

  • IOS画虚线

    UIImageView*imageView1 = [[UIImageViewalloc]initWithFrame...

  • ios画虚线

    项目中用到了自己画的虚线,记录一下:

  • iOS 画虚线

    其中的一个方法 /***画虚线@param lineView 视图@param lineLength 单个虚线大小...

  • iOS 画虚线

    效果图

  • iOS 画线

    1.iOS画虚线边框layer.border 2.iOS画小于1px的细线 3.iOS 设置行距,并且计算有行距的...

  • iOS画虚线 画实线

    // 画虚线- (void)drawRect:(CGRect)rect { CAShapeLayer *dott...

  • ios-画虚线

    需求: 需要实现虚线功能 实现方法: 方法一:使用贝塞尔曲线实现 方法二:Quartz 2D绘制

网友评论

      本文标题:iOS 画虚线

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