Skip to content

Commit d2fc10b

Browse files
committed
Add ability to set star images after initialization
1 parent 9eec3bc commit d2fc10b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

DYRateView/DYRateView/DYRateView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ typedef enum {
4444
@property(nonatomic, assign) CGFloat rate;
4545
@property(nonatomic, assign) CGFloat padding;
4646
@property(nonatomic, assign) BOOL editable;
47+
@property(nonatomic, retain) UIImage *fullStarImage;
48+
@property(nonatomic, retain) UIImage *emptyStarImage;
4749
@property(nonatomic, assign) NSObject<DYRateViewDelegate> *delegate;
4850

4951
- (DYRateView *)initWithFrame:(CGRect)frame;

DYRateView/DYRateView/DYRateView.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ @implementation DYRateView
4444
@synthesize alignment = _alignment;
4545
@synthesize padding = _padding;
4646
@synthesize editable = _editable;
47+
@synthesize fullStarImage = _fullStarImage;
48+
@synthesize emptyStarImage = _emptyStarImage;
4749
@synthesize delegate = _delegate;
4850

4951
- (DYRateView *)initWithFrame:(CGRect)frame {
@@ -144,6 +146,24 @@ - (void)setEditable:(BOOL)editable {
144146
self.userInteractionEnabled = _editable;
145147
}
146148

149+
- (void)setFullStarImage:(UIImage *)fullStarImage
150+
{
151+
if (fullStarImage != _fullStarImage) {
152+
[_fullStarImage release];
153+
_fullStarImage = [fullStarImage retain];
154+
[self setNeedsDisplay];
155+
}
156+
}
157+
158+
- (void)setEmptyStarImage:(UIImage *)emptyStarImage
159+
{
160+
if (emptyStarImage != _emptyStarImage) {
161+
[_emptyStarImage release];
162+
_emptyStarImage = [emptyStarImage retain];
163+
[self setNeedsDisplay];
164+
}
165+
}
166+
147167
- (void)handleTouchAtLocation:(CGPoint)location {
148168
for(int i = _numOfStars - 1; i > -1; i--) {
149169
if (location.x > _origin.x + i * (_fullStarImage.size.width + _padding) - _padding / 2.) {

0 commit comments

Comments
 (0)