前段時間研究鏤空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];
}
希望對你有所幫助, 謝謝!!!