zoukankan      html  css  js  c++  java
  • UIBezierPath 和 CAShapeLayer 绘画图纸

      五角大楼画一个小圆圈戴:

    - (void)drawPentagon{

        //(1)UIBezierPath对象

        UIBezierPath *aPath = [UIBezierPath bezierPath];

        //開始点

        [aPath moveToPoint:CGPointMake(100.0, 1.0)];

        //划线点

        [aPath addLineToPoint:CGPointMake(200.0, 40.0)];

        [aPath addLineToPoint:CGPointMake(160, 140)];

        [aPath addLineToPoint:CGPointMake(40.0, 140)];

        [aPath addLineToPoint:CGPointMake(0.0, 40.0)];

        [aPath closePath];

        

        //设置定点是个5*5的小圆形(自己加的)

        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100-5/2.0, 0, 5, 5)];

        [aPath appendPath:path];

        

        //2)加到CAShapeLayer,效果出来了

        CAShapeLayer *shapelayer = [CAShapeLayer layer];

        //设置边框颜色

        shapelayer.strokeColor = [[UIColor redColor]CGColor];

        //设置填充颜色

        shapelayer.fillColor = [[UIColor whiteColor]CGColor];

        //就是这句话在关联彼此(UIBezierPathCAShapeLayer):

        shapelayer.path = aPath.CGPath;

        [self.view.layer addSublayer:shapelayer];

    }

    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App)
    Charles-安装和配置
    python算法-队列
    python算法-快速排序
    【Codeforces】383.DIV2
    static关键字
    UNIX环境高级编程--5
    【LeetCode】467. Unique Substrings in Wraparound String
    typedef关键字
    strcpy 和 memcpy自实现
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4723207.html
Copyright © 2011-2022 走看看