Skip to content

Commit

Permalink
Added getter of BorderColor and code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
irfangul92 authored and hsousa committed Mar 14, 2017
1 parent ff8935e commit 1d8c873
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
1 change: 0 additions & 1 deletion HCSStarRatingView/HCSStarRatingView.h
Expand Up @@ -43,7 +43,6 @@ IB_DESIGNABLE
@property (nonatomic) IBInspectable CGFloat starBorderWidth;

@property (nonatomic, strong) IBInspectable UIColor *emptyStarColor;
@property (nonatomic, strong) IBInspectable UIColor *filledStarColor;

@property (nonatomic, strong) IBInspectable UIImage *emptyStarImage;
@property (nonatomic, strong) IBInspectable UIImage *halfStarImage;
Expand Down
41 changes: 18 additions & 23 deletions HCSStarRatingView/HCSStarRatingView.m
Expand Up @@ -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

Expand Down Expand Up @@ -63,10 +65,7 @@ - (void)_customInit {
_spacing = 5.f;
_continuous = YES;
_starBorderWidth = 1.0f;
_starBorderColor = self.tintColor;
_emptyStarColor = [UIColor clearColor];
_filledStarColor = self.tintColor;


[self _updateAppearanceForState:self.enabled];
}
Expand Down Expand Up @@ -167,34 +166,30 @@ - (void)setFilledStarImage:(UIImage *)filledStarImage {
}
}


- (void)setFilledStarColor:(UIColor *)filledStarColor {
if(_filledStarColor != filledStarColor) {
_filledStarColor = filledStarColor;
[self setNeedsDisplay];
}
}

- (void)setEmptyStarColor:(UIColor *)emptyStarColor {
if(_emptyStarColor != emptyStarColor) {
if (_emptyStarColor != emptyStarColor) {
_emptyStarColor = emptyStarColor;
[self setNeedsDisplay];
}
}

- (void)setStarBorderColor:(UIColor *)startBorderColor {
if(_starBorderColor != startBorderColor) {
_starBorderColor = startBorderColor;
- (void)setStarBorderColor:(UIColor *)starBorderColor {
if (_starBorderColor != starBorderColor) {
_starBorderColor = starBorderColor;
[self setNeedsDisplay];
}
}

- (void)setStarBorderWidth:(CGFloat)startBorderWidth {
if(startBorderWidth < 0){
startBorderWidth = 0;
- (UIColor *)starBorderColor {
if (_starBorderColor == nil) {
return self.tintColor;
} else {
return _starBorderColor;
}

_starBorderWidth = startBorderWidth;
}

- (void)setStarBorderWidth:(CGFloat)starBorderWidth {
_starBorderWidth = MAX(0, starBorderWidth);
[self setNeedsDisplay];
}

Expand Down Expand Up @@ -288,12 +283,12 @@ - (void)_drawAccurateHalfStarShapeWithFrame:(CGRect)frame tintColor:(UIColor *)t

CGContextSaveGState(UIGraphicsGetCurrentContext()); {
[clipPath addClip];
[_filledStarColor setFill];
[tintColor setFill];
[starShapePath fill];
}
CGContextRestoreGState(UIGraphicsGetCurrentContext());

[_starBorderColor setStroke];
[self.starBorderColor setStroke];
starShapePath.lineWidth = _starBorderWidth;
[starShapePath stroke];
}
Expand All @@ -308,7 +303,7 @@ - (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);
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);
Expand Down

0 comments on commit 1d8c873

Please sign in to comment.