1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| - (void)drawRect:(CGRect)rect { [self setClearsContextBeforeDrawing: YES]; CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef backColorRef = (__bridge CGColorRef)([UIColor blackColor]); CGFloat backLineWidth = 2.f; CGFloat backMiterLimit = 0.f; CGContextSetLineWidth(context, backLineWidth); CGContextSetMiterLimit(context, backMiterLimit); CGContextSetShadowWithColor(context, CGSizeMake(3, 5), 8, backColorRef); CGContextSetLineJoin(context, kCGLineJoinRound); CGContextSetLineCap(context, kCGLineCapRound ); CGContextSetBlendMode(context, kCGBlendModeNormal); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); CGFloat x = self.charW; CGFloat y = self.chartH; for (int i=0; i<vDesc.count; i++) { CGPoint bPoint = CGPointMake(30, y); CGPoint ePoint = CGPointMake(x, y); UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 30, 30)]; int vX = 15; int vY = 30; [label setCenter:CGPointMake(bPoint.x-vX, bPoint.y-vY)]; [label setTextAlignment:NSTextAlignmentCenter]; [label setBackgroundColor:[UIColor clearColor]]; [label setTextColor:[UIColor whiteColor]]; [label setText:[vDesc objectAtIndex:i]]; [self addSubview:label]; CGContextMoveToPoint(context, bPoint.x, bPoint.y-30); CGContextAddLineToPoint(context, ePoint.x, ePoint.y-30); y -= 50; } for (int i=0; i<array.count-1; i++) { CGFloat hY = chartH - 20; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(i*vInterval+10, hY, 60, 30)]; label.transform = CGAffineTransformMakeRotation(0.5); [label setTextAlignment:NSTextAlignmentCenter]; [label setBackgroundColor:[UIColor clearColor]]; [label setTextColor:[UIColor whiteColor]]; label.numberOfLines = 1; label.adjustsFontSizeToFitWidth = YES; label.minimumScaleFactor = 1.0f; [label setText:[hDesc objectAtIndex:i]]; [self addSubview:label]; }
CGColorRef pointColorRef = (__bridge CGColorRef)[UIColor colorWithRed:24.0f/255.0f green:116.0f/255.0f blue:205.0f/255.0f alpha:1.0]; CGFloat pointLineWidth = 1.5f; CGFloat pointMiterLimit = 5.0f; CGContextSetLineWidth(context, pointLineWidth); CGContextSetMiterLimit(context, pointMiterLimit); CGContextSetShadowWithColor(context, CGSizeMake(3, 5), 8, pointColorRef); CGContextSetLineJoin(context, kCGLineJoinRound); CGContextSetLineCap(context, kCGLineCapRound ); CGContextSetBlendMode(context, kCGBlendModeNormal); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGPoint p1 = [[array objectAtIndex:0] CGPointValue]; int yBase = chartH - 30; CGContextMoveToPoint(context, 30, yBase); for (int i = 1; i<[array count]; i++) { p1 = [[array objectAtIndex:i] CGPointValue]; CGPoint goPoint = CGPointMake(p1.x-20, yBase-p1.y*vInterval/20); CGContextAddLineToPoint(context, goPoint.x, goPoint.y);; UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt setBackgroundColor:[UIColor redColor]]; [bt setFrame:CGRectMake(0, 0, 10, 10)]; [bt setCenter:goPoint]; [bt addTarget:self action:@selector(btAction:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:bt]; } CGContextStrokePath(context); }
|