zoukankan      html  css  js  c++  java
  • 画虚线

     1 + (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
     2 {
     3     CAShapeLayer *shapeLayer = [CAShapeLayer layer];
     4     [shapeLayer setBounds:lineView.bounds];
     5     [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
     6     [shapeLayer setFillColor:[UIColor clearColor].CGColor];
     7     //  设置虚线颜色
     8     [shapeLayer setStrokeColor:lineColor.CGColor];    
     9     //  设置虚线宽度
    10     [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    11     [shapeLayer setLineJoin:kCALineJoinRound];   
    12     //  设置线宽,线间距
    13     [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
    14     //  设置路径
    15     CGMutablePathRef path = CGPathCreateMutable();
    16     CGPathMoveToPoint(path, NULL, 0, 0);
    17     CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);   
    18     [shapeLayer setPath:path];
    19     CGPathRelease(path);  
    20     //  把绘制好的虚线添加上来
    21     [lineView.layer addSublayer:shapeLayer];
    22 }
  • 相关阅读:
    快速入门各种跨域
    常用知识点
    比较少用的格式
    git
    “没有用var声明的为全局变量”这种说法不准确
    类数组对象
    函数上下文的变量对象实例
    var a =10 与 a = 10的区别
    原型链与作用域链、执行上下文
    闭包的作用
  • 原文地址:https://www.cnblogs.com/cityingma/p/4934674.html
Copyright © 2011-2022 走看看