iOS简单画圆 圆圈 圆弧 矩形

前段时间研究镂空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简单画圆 圆圈 圆弧 矩形)