美文网首页
iOS简单画圆 圆圈 圆弧 矩形

iOS简单画圆 圆圈 圆弧 矩形

作者: LWide | 来源:发表于2017-09-04 16:19 被阅读0次

    前段时间研究镂空View顺便看了下贝塞尔 下面一个简单的画圆代码 希望对你有所帮助.

    - (void)createCircle

    {

    CGRectframe = [UIScreenmainScreen].bounds;

    UIView* bgView = [[UIViewalloc]initWithFrame:frame];

    bgView.backgroundColor= [UIColorcolorWithWhite:.0falpha:0.5];

    UITapGestureRecognizer* tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(sureTapClick:)];

    [bgViewaddGestureRecognizer:tap];

    [self.viewaddSubview:bgView];

    //这个是圆

    UIBezierPath*path = [UIBezierPathbezierPathWithArcCenter:CGPointMake(frame.size.width-100,100)radius:30startAngle:0endAngle:2*M_PIclockwise:NO];

    //[path appendPath: [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20, 200, self.view.frame.size.width - 100, self.view.frame.size.width - 100)]];

    //这个是矩形

    //[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(frame.size.width/2.0-1, 234, frame.size.width/2.0+1, 55) cornerRadius:5] bezierPathByReversingPath]];

    CAShapeLayer*shapeLayer = [CAShapeLayerlayer];

    shapeLayer.path= path.CGPath;

    shapeLayer.lineWidth=5;

    shapeLayer.strokeColor= [UIColorcyanColor].CGColor;//边框颜色

    shapeLayer.fillColor= [UIColoryellowColor].CGColor;//填充颜色

    [bgView.layeraddSublayer:shapeLayer];

    }

    希望对你有所帮助, 谢谢!!!

    相关文章

      网友评论

          本文标题:iOS简单画圆 圆圈 圆弧 矩形

          本文链接:https://www.haomeiwen.com/subject/imuejxtx.html