日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios 在UIView上画图,线条

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 在UIView上画图,线条 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

1.畫線條(實線,虛線)

- (void)drawRect:(CGRect)rect

{

? ? CGContextRef context = UIGraphicsGetCurrentContext();

? ? [self drawXLine:context rect:rect];

? ? [self drawLegend:context rect:rect];

}

-(CGContextRef)drawXLine:(CGContextRef)context rect:(CGRect)rect {CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);//float partren[] = {2,3};//CGContextSetLineDash(context, 0,partren , 2); //畫虛線 CGContextMoveToPoint(context, 10, 0);CGContextAddLineToPoint(context, 0, 100);CGContextStrokePath(context);return context; }

2.畫圖例說明

//畫圖例說明 -(void)drawLegend:(CGContextRef)context rect:(CGRect)_rect {CGSize myShadowOffset = CGSizeMake (2, 2);//矩形和陰影的位置 CGContextSaveGState(context);CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1].CGColor);CGContextSetShadow (context, myShadowOffset, 2); //背景的陰影CGContextFillRect(context, CGRectMake(self.frame.size.width/2-100, [UIScreen mainScreen].bounds.size.height-80, 200, 25.0));NSArray *groupTitle = [NSArray arrayWithObjects:@"提出問題數量",@"方案采納數量", nil];int legendCount = [groupTitle count];int stepWidth = 15;for (int i = 0; i < legendCount; i++) {if (i == 0){//設定第一個圖例的顏色CGContextSetFillColorWithColor(context, [UIColor colorWithRed:64.0/255.0 green:104.0/255.0 blue:168.0/255.0 alpha:1.0].CGColor);}else {//設定第二個圖例的顏色CGContextSetFillColorWithColor(context, [UIColor colorWithRed:240.0/255.0 green:152.0/255.0 blue:56.0/255.0 alpha:1.0].CGColor);}CGContextSetShadow (context, myShadowOffset, 1);CGContextFillRect(context, CGRectMake(stepWidth + 50, [UIScreen mainScreen].bounds.size.height-72, 10, 10)); //小方塊的大小以及位置 UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(stepWidth+65, [UIScreen mainScreen].bounds.size.height-76, _rect.size.width, 18)]; //聲明UIlbel并指定其位置和長寬label2.backgroundColor = [UIColor clearColor]; //設置label的背景色,這里設置為透明色。label2.font = [UIFont fontWithName:@"Helvetica-Bold" size:12]; //設置label的字體和字體大小。//label2.transform = CGAffineTransformMakeRotation(0.1); //設置label的旋轉角度label2.text = [groupTitle objectAtIndex:i]; //設置label所顯示的文本label2.textColor = [UIColor blackColor]; //設置文本的顏色label2.textAlignment =NSTextAlignmentLeft; //設置文本在label中顯示的位置,這里為居中。 [self addSubview:label2];stepWidth += 100;}CGContextRestoreGState(context); }

?

---恢復內容結束---

轉載于:https://www.cnblogs.com/lihaibo-Leao/p/3260032.html

總結

以上是生活随笔為你收集整理的ios 在UIView上画图,线条的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。