首页 > 其他 > 详细

UIBezierPath 和 CAShapeLayer 画画图

时间:2014-07-24 23:27:33      阅读:413      评论:0      收藏:0      [点我收藏+]

  画一个头戴小圆的五边形:

- (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];

}

UIBezierPath 和 CAShapeLayer 画画图,布布扣,bubuko.com

UIBezierPath 和 CAShapeLayer 画画图

原文:http://blog.csdn.net/u014624597/article/details/38088997

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!