diff --git a/HCSStarRatingView/HCSStarRatingView.h b/HCSStarRatingView/HCSStarRatingView.h index 007ab69..04e483b 100644 --- a/HCSStarRatingView/HCSStarRatingView.h +++ b/HCSStarRatingView/HCSStarRatingView.h @@ -39,6 +39,11 @@ IB_DESIGNABLE // Optional: if `nil` method will return `NO`. @property (nonatomic, copy) HCSStarRatingViewShouldBeginGestureRecognizerBlock shouldBeginGestureRecognizerBlock; +@property (nonatomic, strong) IBInspectable UIColor *starBorderColor; +@property (nonatomic) IBInspectable CGFloat starBorderWidth; + +@property (nonatomic, strong) IBInspectable UIColor *emptyStarColor; + @property (nonatomic, strong) IBInspectable UIImage *emptyStarImage; @property (nonatomic, strong) IBInspectable UIImage *halfStarImage; @property (nonatomic, strong) IBInspectable UIImage *filledStarImage; diff --git a/HCSStarRatingView/HCSStarRatingView.m b/HCSStarRatingView/HCSStarRatingView.m index 9a3fea8..4e9ad8c 100644 --- a/HCSStarRatingView/HCSStarRatingView.m +++ b/HCSStarRatingView/HCSStarRatingView.m @@ -30,12 +30,14 @@ @implementation HCSStarRatingView { CGFloat _minimumValue; NSUInteger _maximumValue; CGFloat _value; + UIColor *_starBorderColor; } @dynamic minimumValue; @dynamic maximumValue; @dynamic value; @dynamic shouldUseImages; +@dynamic starBorderColor; #pragma mark - Initialization @@ -62,6 +64,9 @@ - (void)_customInit { _value = 0; _spacing = 5.f; _continuous = YES; + _starBorderWidth = 1.0f; + _emptyStarColor = [UIColor clearColor]; + [self _updateAppearanceForState:self.enabled]; } @@ -161,6 +166,34 @@ - (void)setFilledStarImage:(UIImage *)filledStarImage { } } +- (void)setEmptyStarColor:(UIColor *)emptyStarColor { + if (_emptyStarColor != emptyStarColor) { + _emptyStarColor = emptyStarColor; + [self setNeedsDisplay]; + } +} + +- (void)setStarBorderColor:(UIColor *)starBorderColor { + if (_starBorderColor != starBorderColor) { + _starBorderColor = starBorderColor; + [self setNeedsDisplay]; + } +} + +- (UIColor *)starBorderColor { + if (_starBorderColor == nil) { + return self.tintColor; + } else { + return _starBorderColor; + } +} + +- (void)setStarBorderWidth:(CGFloat)starBorderWidth { + _starBorderWidth = MAX(0, starBorderWidth); + [self setNeedsDisplay]; +} + + - (BOOL)shouldUseImages { return (self.emptyStarImage!=nil && self.filledStarImage!=nil); } @@ -245,6 +278,9 @@ - (void)_drawAccurateHalfStarShapeWithFrame:(CGRect)frame tintColor:(UIColor *)t [clipPath appendPath:[UIBezierPath bezierPathWithRect:rightRectOfStar]]; clipPath.usesEvenOddFillRule = YES; + [_emptyStarColor setFill]; + [starShapePath fill]; + CGContextSaveGState(UIGraphicsGetCurrentContext()); { [clipPath addClip]; [tintColor setFill]; @@ -252,8 +288,8 @@ - (void)_drawAccurateHalfStarShapeWithFrame:(CGRect)frame tintColor:(UIColor *)t } CGContextRestoreGState(UIGraphicsGetCurrentContext()); - [tintColor setStroke]; - starShapePath.lineWidth = 1; + [self.starBorderColor setStroke]; + starShapePath.lineWidth = _starBorderWidth; [starShapePath stroke]; } @@ -267,6 +303,8 @@ - (void)drawRect:(CGRect)rect { CGFloat availableWidth = rect.size.width - (_spacing * (_maximumValue - 1)) - 2; CGFloat cellWidth = (availableWidth / _maximumValue); CGFloat starSide = (cellWidth <= rect.size.height) ? cellWidth : rect.size.height; + starSide = (self.shouldUseImages) ? starSide : (starSide - _starBorderWidth); + for (int idx = 0; idx < _maximumValue; idx++) { CGPoint center = CGPointMake(cellWidth*idx + cellWidth/2 + _spacing*idx + 1, rect.size.height/2); CGRect frame = CGRectMake(center.x - starSide/2, center.y - starSide/2, starSide, starSide);