Today's Menu  Portugal
journal and plan nutrition
Instance Methods | Protected Attributes | Properties | List of all members
DLStarRatingControl Class Reference

#import <DLStarRatingControl.h>

Inheritance diagram for DLStarRatingControl:
Inheritance graph
[legend]
Collaboration diagram for DLStarRatingControl:
Collaboration graph
[legend]

Instance Methods

(id) - initWithFrame:
 
(id) - initWithFrame:andStars:isFractional:
 
(void) - setStar:highlightedStar:
 
(void) - setStar:highlightedStar:atIndex:
 
(void) - setupView [implementation]
 
(id) - initWithCoder: [implementation]
 
(void) - layoutSubviews [implementation]
 
(UIButton *) - starForPoint: [implementation]
 
(void) - disableStarsDownToExclusive: [implementation]
 
(void) - disableStarsDownTo: [implementation]
 
(void) - enableStarsUpTo: [implementation]
 
(BOOL) - beginTrackingWithTouch:withEvent: [implementation]
 
(void) - cancelTrackingWithEvent: [implementation]
 
(BOOL) - continueTrackingWithTouch:withEvent: [implementation]
 
(void) - endTrackingWithTouch:withEvent: [implementation]
 
(void) - setRating: [implementation]
 
(void) - dealloc [implementation]
 

Protected Attributes

int numberOfStars
 
int currentIdx
 

Properties

UIImage * star
 
UIImage * highlightedStar
 
float rating
 
id< DLStarRatingDelegatedelegate
 
BOOL isFractionalRatingEnabled
 

Detailed Description

Definition at line 20 of file DLStarRatingControl.h.

Method Documentation

◆ beginTrackingWithTouch:withEvent:()

- (BOOL) beginTrackingWithTouch: (UITouch *)  touch
withEvent: (UIEvent *)  event 
implementation

Definition at line 134 of file DLStarRatingControl.m.

134  :(UITouch *)touch withEvent:(UIEvent *)event {
135  CGPoint point = [touch locationInView:self];
136  UIButton *pressedButton = [self starForPoint:point];
137  if (pressedButton) {
138  int idx = (int)pressedButton.tag;
139  if (pressedButton.highlighted) {
140  [self disableStarsDownToExclusive:idx];
141  } else {
142  [self enableStarsUpTo:idx];
143  }
144  currentIdx = idx;
145  }
146  return YES;
147 }

◆ cancelTrackingWithEvent:()

- (void) cancelTrackingWithEvent: (UIEvent *)  event
implementation

Definition at line 149 of file DLStarRatingControl.m.

149  :(UIEvent *)event {
150  [super cancelTrackingWithEvent:event];
151 }

◆ continueTrackingWithTouch:withEvent:()

- (BOOL) continueTrackingWithTouch: (UITouch *)  touch
withEvent: (UIEvent *)  event 
implementation

Definition at line 153 of file DLStarRatingControl.m.

153  :(UITouch *)touch withEvent:(UIEvent *)event {
154  CGPoint point = [touch locationInView:self];
155 
156  UIButton *pressedButton = [self starForPoint:point];
157  if (pressedButton) {
158  int idx = (int)pressedButton.tag;
159  UIButton *currentButton = (UIButton*)[self subViewWithTag:currentIdx];
160 
161  if (idx < currentIdx) {
162  currentButton.highlighted = NO;
163  currentIdx = idx;
164  [self disableStarsDownToExclusive:idx];
165  } else if (idx > currentIdx) {
166  currentButton.highlighted = YES;
167  pressedButton.highlighted = YES;
168  currentIdx = idx;
169  [self enableStarsUpTo:idx];
170  }
171  } else if (point.x < [self subViewWithTag:0].frame.origin.x) {
172  ((UIButton*)[self subViewWithTag:0]).highlighted = NO;
173  currentIdx = -1;
174  [self disableStarsDownToExclusive:0];
175  }
176  return YES;
177 }

◆ dealloc()

- (void) dealloc
implementation

Definition at line 207 of file DLStarRatingControl.m.

207  {
208  self.star = nil;
209  self.highlightedStar = nil;
210  self.delegate = nil;
211  // [super dealloc];
212 }

◆ disableStarsDownTo:()

- (void) disableStarsDownTo: (int)  idx
implementation

Definition at line 119 of file DLStarRatingControl.m.

119  :(int)idx {
120  for (int i=numberOfStars; i >= idx; --i) {
121  UIButton *b = (UIButton*)[self subViewWithTag:i];
122  b.highlighted = NO;
123  }
124 }

◆ disableStarsDownToExclusive:()

- (void) disableStarsDownToExclusive: (int)  idx
implementation

Definition at line 112 of file DLStarRatingControl.m.

112  :(int)idx {
113  for (int i=numberOfStars; i > idx; --i) {
114  UIButton *b = (UIButton*)[self subViewWithTag:i];
115  b.highlighted = NO;
116  }
117 }

◆ enableStarsUpTo:()

- (void) enableStarsUpTo: (int)  idx
implementation

Definition at line 127 of file DLStarRatingControl.m.

127  :(int)idx {
128  for (int i=0; i <= idx; i++) {
129  UIButton *b = (UIButton*)[self subViewWithTag:i];
130  b.highlighted = YES;
131  }
132 }

◆ endTrackingWithTouch:withEvent:()

- (void) endTrackingWithTouch: (UITouch *)  touch
withEvent: (UIEvent *)  event 
implementation

Definition at line 179 of file DLStarRatingControl.m.

179  :(UITouch *)touch withEvent:(UIEvent *)event {
180  [self.delegate newRating:self :self.rating];
181  [super endTrackingWithTouch:touch withEvent:event];
182 }

◆ initWithCoder:()

- (id) initWithCoder: (NSCoder *)  aDecoder
implementation

Definition at line 37 of file DLStarRatingControl.m.

37  :(NSCoder *)aDecoder {
38  self = [super initWithCoder:aDecoder];
39  if (self) {
43  [self setupView];
44  }
45  return self;
46 }
#define kNumberOfFractions
#define kDefaultNumberOfStars

◆ initWithFrame:()

- (id) initWithFrame: (CGRect)  frame

Definition at line 48 of file DLStarRatingControl.m.

48  :(CGRect)frame {
49  self = [super initWithFrame:frame];
50  if (self) {
54  [self setupView];
55 
56  }
57  return self;
58 }
#define kNumberOfFractions
#define kDefaultNumberOfStars

◆ initWithFrame:andStars:isFractional:()

- (id) initWithFrame: (CGRect)  frame
andStars: (NSUInteger)  _numberOfStars
isFractional: (BOOL)  isFract 

Definition at line 60 of file DLStarRatingControl.m.

60  :(CGRect)frame andStars:(NSUInteger)_numberOfStars isFractional:(BOOL)isFract{
61  self = [super initWithFrame:frame];
62  if (self) {
63  isFractionalRatingEnabled = isFract;
64  numberOfStars = (int)_numberOfStars;
67  [self setupView];
68  }
69  return self;
70 }
#define kNumberOfFractions

◆ layoutSubviews()

- (void) layoutSubviews
implementation

Definition at line 72 of file DLStarRatingControl.m.

72  {
73  for (int i=0; i < numberOfStars; i++) {
74  [(DLStarView*)[self subViewWithTag:i] centerIn:self.frame with:numberOfStars];
75  }
76 }

◆ setRating:()

- (void) setRating: (float)  _rating
implementation

Definition at line 187 of file DLStarRatingControl.m.

187  :(float)_rating {
189  _rating *=kNumberOfFractions;
190  }
191  [self disableStarsDownTo:0];
192  currentIdx = (int)_rating-1;
193  [self enableStarsUpTo:currentIdx];
194 }
#define kNumberOfFractions

◆ setStar:highlightedStar:()

- (void) setStar: (UIImage*)  defaultStarImage
highlightedStar: (UIImage*)  highlightedStarImage 

Definition at line 81 of file DLStarRatingControl.m.

81  :(UIImage*)defaultStarImage highlightedStar:(UIImage*)highlightedStarImage {
82  for(NSInteger i = 0; i < numberOfStars; i++){
83  [self setStar:defaultStarImage highlightedStar:highlightedStarImage atIndex:(int)i];
84  }
85 }

◆ setStar:highlightedStar:atIndex:()

- (void) setStar: (UIImage*)  defaultStarImage
highlightedStar: (UIImage*)  highlightedStarImage
atIndex: (int)  index 

Definition at line 87 of file DLStarRatingControl.m.

87  :(UIImage*)defaultStarImage highlightedStar:(UIImage*)highlightedStarImage atIndex:(int)index {
88  DLStarView *selectedStar = (DLStarView*)[self subViewWithTag:index];
89 
90  // check if star exists
91  if (!selectedStar) return;
92 
93  // check images for nil else use default stars
94  defaultStarImage = (defaultStarImage) ? defaultStarImage : star;
95  highlightedStarImage = (highlightedStarImage) ? highlightedStarImage : highlightedStar;
96 
97  [selectedStar setStarImage:defaultStarImage highlightedStarImage:highlightedStarImage];
98 }
void setStarImage:highlightedStarImage:(UIImage *starImage, [highlightedStarImage] UIImage *highlightedImage)
Definition: DLStarView.m:81

◆ setupView()

- (void) setupView
implementation

Definition at line 25 of file DLStarRatingControl.m.

25  {
26  self.clipsToBounds = YES;
27  currentIdx = -1;
28  star = [UIImage imageNamed:@"star.png"];
29  highlightedStar = [UIImage imageNamed:@"star_highlighted.png"];
30 
31  for (int i=0; i<numberOfStars; i++) {
32  DLStarView *v = [[DLStarView alloc] initWithDefault:self.star highlighted:self.highlightedStar position:i allowFractions:isFractionalRatingEnabled];
33  [self addSubview:v];
34  }
35 }

◆ starForPoint:()

- (UIButton *) starForPoint: (CGPoint)  point
implementation

Definition at line 103 of file DLStarRatingControl.m.

103  :(CGPoint)point {
104  for (int i=0; i < numberOfStars; i++) {
105  if (CGRectContainsPoint([self subViewWithTag:i].frame, point)) {
106  return (UIButton*)[self subViewWithTag:i];
107  }
108  }
109  return nil;
110 }

Member Data Documentation

◆ currentIdx

- (int) currentIdx
protected

Definition at line 22 of file DLStarRatingControl.h.

◆ numberOfStars

- (int) numberOfStars
protected

Definition at line 21 of file DLStarRatingControl.h.

Property Documentation

◆ delegate

- (id<DLStarRatingDelegate>) delegate
readwritenonatomicassign

Definition at line 37 of file DLStarRatingControl.h.

◆ highlightedStar

- (UIImage *) highlightedStar
readwritenonatomicretain

Definition at line 24 of file DLStarRatingControl.h.

◆ isFractionalRatingEnabled

- (BOOL) isFractionalRatingEnabled
readwritenonatomicassign

Definition at line 26 of file DLStarRatingControl.h.

◆ rating

- (float) rating
readwritenonatomicassign

Definition at line 36 of file DLStarRatingControl.h.

◆ star

- (UIImage *) star
readwritenonatomicretain

Definition at line 23 of file DLStarRatingControl.h.


The documentation for this class was generated from the following files: