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

}

希望對你有所幫助, 謝謝!!!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容