ios 在UIView上画图,线条
生活随笔
收集整理的這篇文章主要介紹了
ios 在UIView上画图,线条
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
1.畫(huà)線條(實(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); //畫(huà)虛線 CGContextMoveToPoint(context, 10, 0);CGContextAddLineToPoint(context, 0, 100);CGContextStrokePath(context);return context; }2.畫(huà)圖例說(shuō)明
//畫(huà)圖例說(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)題。
- 上一篇: drools规则引擎源码解析
- 下一篇: 扒站工具Teleport Pro教程