Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
PNChart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Orlando Aleman Ortiz
2014-04-21 19:14:56 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6699f98abb70565d210175a5fd8eb7d36f8f5cb5
6699f98a
1 parent
1d65317a
- Detects touches on the bars and, if implemented, calls to the delegated method.
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
0 deletions
PNChart/PNBarChart.h
PNChart/PNBarChart.m
PNChart/PNChartDelegate.h
PNChartDemo/PCChartsTableViewController.m
PNChart/PNBarChart.h
View file @
6699f98
...
...
@@ -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
...
...
PNChart/PNBarChart.m
View file @
6699f98
...
...
@@ -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
...
...
PNChart/PNChartDelegate.h
View file @
6699f98
...
...
@@ -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
\ No newline at end of file
...
...
PNChartDemo/PCChartsTableViewController.m
View file @
6699f98
...
...
@@ -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
...
...
Please
register
or
login
to post a comment