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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ios 在UIView上画图,线条

發(fā)布時(shí)間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 在UIView上画图,线条 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

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

- (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.畫圖例說(shuō)明

//畫圖例說(shuō)明 -(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:@"提出問(wèn)題數(shù)量",@"方案采納數(shù)量", nil];int legendCount = [groupTitle count];int stepWidth = 15;for (int i = 0; i < legendCount; i++) {if (i == 0){//設(shè)定第一個(gè)圖例的顏色CGContextSetFillColorWithColor(context, [UIColor colorWithRed:64.0/255.0 green:104.0/255.0 blue:168.0/255.0 alpha:1.0].CGColor);}else {//設(shè)定第二個(gè)圖例的顏色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并指定其位置和長(zhǎng)寬label2.backgroundColor = [UIColor clearColor]; //設(shè)置label的背景色,這里設(shè)置為透明色。label2.font = [UIFont fontWithName:@"Helvetica-Bold" size:12]; //設(shè)置label的字體和字體大小。//label2.transform = CGAffineTransformMakeRotation(0.1); //設(shè)置label的旋轉(zhuǎn)角度label2.text = [groupTitle objectAtIndex:i]; //設(shè)置label所顯示的文本label2.textColor = [UIColor blackColor]; //設(shè)置文本的顏色label2.textAlignment =NSTextAlignmentLeft; //設(shè)置文本在label中顯示的位置,這里為居中。 [self addSubview:label2];stepWidth += 100;}CGContextRestoreGState(context); }

?

---恢復(fù)內(nèi)容結(jié)束---

轉(zhuǎn)載于:https://www.cnblogs.com/lihaibo-Leao/p/3260032.html

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。