23 #pragma mark Initialization 26 self.clipsToBounds = YES;
28 star = [UIImage imageNamed:@"star.png"];
32 DLStarView *v = [[
DLStarView alloc] initWithDefault:self.star highlighted:self.highlightedStar position:i allowFractions:isFractionalRatingEnabled];
37 - (id)initWithCoder:(NSCoder *)aDecoder {
38 self = [
super initWithCoder:aDecoder];
48 - (id)initWithFrame:(CGRect)frame {
49 self = [
super initWithFrame:frame];
60 - (id)initWithFrame:(CGRect)frame andStars:(NSUInteger)_numberOfStars isFractional:(BOOL)isFract{
61 self = [
super initWithFrame:frame];
74 [(
DLStarView*)[
self subViewWithTag:i] centerIn:self.frame with:numberOfStars];
79 #pragma mark Customization 81 - (void)setStar:(UIImage*)defaultStarImage highlightedStar:(UIImage*)highlightedStarImage {
87 - (void)setStar:(UIImage*)defaultStarImage highlightedStar:(UIImage*)highlightedStarImage atIndex:(
int)index {
91 if (!selectedStar)
return;
94 defaultStarImage = (defaultStarImage) ? defaultStarImage :
star;
95 highlightedStarImage = (highlightedStarImage) ? highlightedStarImage :
highlightedStar;
101 #pragma mark Touch Handling 103 - (UIButton*)starForPoint:(CGPoint)point {
105 if (CGRectContainsPoint([
self subViewWithTag:i].frame, point)) {
106 return (UIButton*)[
self subViewWithTag:i];
112 - (void)disableStarsDownToExclusive:(
int)idx {
114 UIButton *b = (UIButton*)[
self subViewWithTag:i];
119 - (void)disableStarsDownTo:(
int)idx {
121 UIButton *b = (UIButton*)[
self subViewWithTag:i];
127 - (void)enableStarsUpTo:(
int)idx {
128 for (
int i=0; i <= idx; i++) {
129 UIButton *b = (UIButton*)[
self subViewWithTag:i];
134 - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
135 CGPoint point = [touch locationInView:self];
138 int idx = (int)pressedButton.tag;
139 if (pressedButton.highlighted) {
149 - (void)cancelTrackingWithEvent:(UIEvent *)event {
150 [
super cancelTrackingWithEvent:event];
153 - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
154 CGPoint point = [touch locationInView:self];
158 int idx = (int)pressedButton.tag;
159 UIButton *currentButton = (UIButton*)[
self subViewWithTag:currentIdx];
162 currentButton.highlighted = NO;
166 currentButton.highlighted = YES;
167 pressedButton.highlighted = YES;
171 }
else if (point.x < [
self subViewWithTag:0].frame.origin.x) {
172 ((UIButton*)[
self subViewWithTag:0]).highlighted = NO;
179 - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
180 [
self.delegate newRating:self :self.rating];
181 [
super endTrackingWithTouch:touch withEvent:event];
185 #pragma mark Rating Property 187 - (void)setRating:(
float)_rating {
205 #pragma mark Memory Management 209 self.highlightedStar = nil;
UIImage * highlightedStar
UIButton * starForPoint:(CGPoint point)
void setStarImage:highlightedStarImage:(UIImage *starImage, [highlightedStarImage] UIImage *highlightedImage)
id< U7ParamEditControlDelegate > delegate
#define kNumberOfFractions
void disableStarsDownToExclusive:(int idx)
#define kDefaultNumberOfStars
void enableStarsUpTo:(int idx)
void setStar:highlightedStar:atIndex:(UIImage *defaultStarImage, [highlightedStar] UIImage *highlightedStarImage, [atIndex] int index)
BOOL isFractionalRatingEnabled
void disableStarsDownTo:(int idx)