Orlando Aleman Ortiz

- Detects touches on the bars and, if implemented, calls to the delegated method.

... ... @@ -7,6 +7,7 @@
//
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#define chartMargin 10
#define xLabelMargin 15
... ... @@ -32,4 +33,5 @@
@property (nonatomic) UIColor *barBackgroundColor;
@property (nonatomic) BOOL showLabel;
@property (nonatomic, retain) id<PNChartDelegate> delegate;
@end
... ...
... ... @@ -119,6 +119,7 @@
bar.backgroundColor = _barBackgroundColor;
bar.barColor = [self barColorAtIndex:index];
bar.grade = grade;
bar.tag = index;
[_bars addObject:bar];
[self addSubview:bar];
... ... @@ -149,4 +150,26 @@
}
#pragma mark - Touch detection
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchPoint:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
- (void)touchPoint:(NSSet *)touches withEvent:(UIEvent *)event
{
//Get the point user touched
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
UIView *subview = [self hitTest:touchPoint withEvent:nil];
if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarCharIndex:)]) {
[self.delegate userClickedOnBarCharIndex:subview.tag];
}
}
@end
... ...
... ... @@ -22,5 +22,10 @@
*/
- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex andPointIndex:(NSInteger)pointIndex;
/**
* When user click on a chart bar
*
*/
- (void)userClickedOnBarCharIndex:(NSInteger)barIndex;
@end
@end
\ No newline at end of file
... ...
... ... @@ -111,6 +111,8 @@
[barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]];
[barChart strokeChart];
barChart.delegate = self;
[viewController.view addSubview:barChartLabel];
[viewController.view addSubview:barChart];
... ... @@ -148,4 +150,9 @@
NSLog(@"Click on line %f, %f, line index is %d",point.x, point.y, (int)lineIndex);
}
- (void)userClickedOnBarCharIndex:(NSInteger)barIndex
{
NSLog(@"Click on bar %@", @(barIndex));
}
@end
... ...