New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added star empty state color, border color and border width #48
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,12 @@ - (void)_customInit { | |
_value = 0; | ||
_spacing = 5.f; | ||
_continuous = YES; | ||
_starBorderWidth = 1.0f; | ||
_starBorderColor = self.tintColor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be set here, because if the tint color changes and we haven't set a custom border color, this would result in different colors for existing apps (which means we're braking API behaviour). My suggestion is that we have a getter for This way if a developer already using this control updates the pod/code and doesn't care/know about custom border colors, his/her code won't break when (s)he tries to change the tint color. What do you think? |
||
_emptyStarColor = [UIColor clearColor]; | ||
_filledStarColor = self.tintColor; | ||
|
||
|
||
[self _updateAppearanceForState:self.enabled]; | ||
} | ||
|
||
|
@@ -161,6 +167,38 @@ - (void)setFilledStarImage:(UIImage *)filledStarImage { | |
} | ||
} | ||
|
||
|
||
- (void)setFilledStarColor:(UIColor *)filledStarColor { | ||
if(_filledStarColor != filledStarColor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you put a space after the |
||
_filledStarColor = filledStarColor; | ||
[self setNeedsDisplay]; | ||
} | ||
} | ||
|
||
- (void)setEmptyStarColor:(UIColor *)emptyStarColor { | ||
if(_emptyStarColor != emptyStarColor) { | ||
_emptyStarColor = emptyStarColor; | ||
[self setNeedsDisplay]; | ||
} | ||
} | ||
|
||
- (void)setStarBorderColor:(UIColor *)startBorderColor { | ||
if(_starBorderColor != startBorderColor) { | ||
_starBorderColor = startBorderColor; | ||
[self setNeedsDisplay]; | ||
} | ||
} | ||
|
||
- (void)setStarBorderWidth:(CGFloat)startBorderWidth { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in variable name: should be |
||
if(startBorderWidth < 0){ | ||
startBorderWidth = 0; | ||
} | ||
|
||
_starBorderWidth = startBorderWidth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the What the |
||
[self setNeedsDisplay]; | ||
} | ||
|
||
|
||
- (BOOL)shouldUseImages { | ||
return (self.emptyStarImage!=nil && self.filledStarImage!=nil); | ||
} | ||
|
@@ -245,15 +283,18 @@ - (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]; | ||
[_filledStarColor setFill]; | ||
[starShapePath fill]; | ||
} | ||
CGContextRestoreGState(UIGraphicsGetCurrentContext()); | ||
|
||
[tintColor setStroke]; | ||
starShapePath.lineWidth = 1; | ||
[_starBorderColor setStroke]; | ||
starShapePath.lineWidth = _starBorderWidth; | ||
[starShapePath stroke]; | ||
} | ||
|
||
|
@@ -267,6 +308,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space before Also, why is here exactly? (seriously, I'm asking out of ignorance 😆 and only proves how much I need to take another good look at my own code again) |
||
|
||
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't have a separate property for
filled
. The idea is to usetintColor
whenever possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggested change done.