iOS绘圆形图-CGContextAddArc各参数说明
生活随笔
收集整理的這篇文章主要介紹了
iOS绘圆形图-CGContextAddArc各参数说明
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
1.使用 UIGraphicsGetCurrentContext() 畫圓
? ? CGContextAddArc(<#CGContextRef? _Nullable c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#int clockwise#>)
x,y為圓點坐標,radius半徑,startAngle為開始的弧度,endAngle為 結束的弧度,clockwise 0為順時針,1為逆時針。
-(void)drawRect:(CGRect)rect{CGFloat lineWidth = 12;NSInteger sleepScore = arc4random() % 101;//定義一個不透明類型的Quartz 2D繪畫環境,相當于一個畫布CGContextRef context = UIGraphicsGetCurrentContext();[[UIColor whiteColor] set];CGContextFillRect(context, rect);//有值圓CGFloat scoreLine = sleepScore/100.0;Log(@"sleepScore %ld %f",sleepScore,scoreLine);CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"#48BBAD"].CGColor);CGContextSetLineWidth(context, lineWidth);CGContextAddArc(context, rect.size.width/2,rect.size.height, rect.size.width/2-lineWidth/2, -M_PI, -M_PI/4, 0);// 0為順時針,1為逆時針CGContextDrawPath(context, kCGPathStroke);/*寫分數*/CGFloat fontSize = (rect.size.height-lineWidth)*0.7;CGRect scoreRect = CGRectMake(rect.size.width/2-fontSize, rect.size.height-fontSize, fontSize*2, fontSize);[self drawTextWithContent:@"100" WithFontSize:fontSize WithWeight:1 withTextColor:[UIColor blackColor] withRect:scoreRect withAlignment:NSTextAlignmentCenter]; } -(void)drawTextWithContent:(NSString *)text WithFontSize:(CGFloat)fontSize WithWeight:(CGFloat)weight withTextColor:(UIColor *)textColor withRect:(CGRect)rect withAlignment:(NSTextAlignment)alignment{// Log(@"fontSize:%f",fontSize);NSMutableDictionary *attributesDic = [NSMutableDictionary dictionary];attributesDic[NSFontAttributeName] = [UIFont systemFontOfSize:fontSize weight:weight];attributesDic[NSForegroundColorAttributeName] = textColor;//段落格式NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];textStyle.lineBreakMode = NSLineBreakByWordWrapping;textStyle.alignment = alignment;//對齊方式attributesDic[NSParagraphStyleAttributeName] = textStyle;[text drawInRect:rect withAttributes:attributesDic]; }?
轉載于:https://my.oschina.net/u/2365397/blog/1583670
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的iOS绘圆形图-CGContextAddArc各参数说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 南风知我意吹梦到西洲怎么回复
- 下一篇: 梦到弟弟腿受伤了是什么意思