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 }
  • 相关阅读:
    python装饰器
    python名称空间和作用域
    python函数-函数对象
    python函数-参数
    python文件高级操作
    python基本文件操作
    python2和3的区别
    OSI-传输层
    Android屏幕density, dip等相关概念总结
    架构设计:系统间通信(20)——MQ:消息协议(下)
  • 原文地址:https://www.cnblogs.com/rglmuselily/p/6084719.html
Copyright © 2011-2022 走看看