zoukankan      html  css  js  c++  java
  • iOS之绘制虚线

     1 /*
     2   ** lineFrame:     虚线的 frame
     3   ** length:        虚线中短线的宽度
     4   ** spacing:       虚线中短线之间的间距
     5   ** color:         虚线中短线的颜色
     6 */
     7 + (UIView *)createDashedLineWithFrame:(CGRect)lineFrame
     8                            lineLength:(int)length
     9                           lineSpacing:(int)spacing
    10                             lineColor:(UIColor *)color{
    11     UIView *dashedLine = [[UIView alloc] initWithFrame:lineFrame];
    12     dashedLine.backgroundColor = [UIColor clearColor];
    13     CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    14     [shapeLayer setBounds:dashedLine.bounds];
    15     [shapeLayer setPosition:CGPointMake(CGRectGetWidth(dashedLine.frame) / 2, CGRectGetHeight(dashedLine.frame))];
    16     [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    17     [shapeLayer setStrokeColor:color.CGColor];
    18     [shapeLayer setLineWidth:CGRectGetHeight(dashedLine.frame)];
    19     [shapeLayer setLineJoin:kCALineJoinRound];
    20     [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:length], [NSNumber numberWithInt:spacing], nil]];
    21     CGMutablePathRef path = CGPathCreateMutable();
    22     CGPathMoveToPoint(path, NULL, 0, 0);
    23     CGPathAddLineToPoint(path, NULL, CGRectGetWidth(dashedLine.frame), 0);
    24     [shapeLayer setPath:path];
    25     CGPathRelease(path);
    26     [dashedLine.layer addSublayer:shapeLayer];
    27     return dashedLine;
    28 }
  • 相关阅读:
    SQL的介绍及MySQL的安装
    git中级技能
    git基本用法
    git基本语法
    出租车数据分析
    使用Spark MLlib进行情感分析
    增量式编码器专题
    vue-loader的简单例子
    node爬虫(转)
    fs-extra 文件管理
  • 原文地址:https://www.cnblogs.com/rglmuselily/p/6084719.html
Copyright © 2011-2022 走看看