Skip to content
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

Merged
merged 2 commits into from Mar 14, 2017

Conversation

irfangul92
Copy link
Contributor

@irfangul92 irfangul92 commented Nov 4, 2016

This will allow to change the empty state color, so we will be able use separate colors for star fill state and empty state. In addition star border color and width properties are also configurable through IBInspectable. This will cover most of the UI variations if you want to stick with stars for rating.

screen shot 2016-11-04 at 4 01 28 pm

screen shot 2016-11-04 at 4 01 51 pm

star border colour and border width
@@ -161,6 +167,38 @@ - (void)setFilledStarImage:(UIImage *)filledStarImage {
}
}


- (void)setFilledStarColor:(UIColor *)filledStarColor {
if(_filledStarColor != filledStarColor) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a space after the if please? I'm planning on doing a major code style change on this library soon, but my OCD won't allow me to merge this without a space there 😆

@property (nonatomic) IBInspectable CGFloat starBorderWidth;

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

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 use tintColor whenever possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested change done.

@@ -62,6 +62,12 @@ - (void)_customInit {
_value = 0;
_spacing = 5.f;
_continuous = YES;
_starBorderWidth = 1.0f;
_starBorderColor = self.tintColor;
Copy link
Owner

Choose a reason for hiding this comment

The 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 starBorderColor that returns _starBorderColor if it's not nil, and self.tintColor otherwise.

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?

startBorderWidth = 0;
}

_starBorderWidth = startBorderWidth;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the if above, why not just _starBorderWidth = MAX(0, starBorderWidth)?

What the if should be doing is validating if _starBorderWidth != starBorderWidth, similarly to the implementation in the other setters.

}
}

- (void)setStarBorderWidth:(CGFloat)startBorderWidth {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in variable name: should be starBorderWidth and not startBorderWidth 🙂

@@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The 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)

@irfangul92
Copy link
Contributor Author

Done

@irfangul92 irfangul92 changed the title Added star fill state color, empty state color, border color and border width Added star empty state color, border color and border width Nov 7, 2016
@hsousa
Copy link
Owner

hsousa commented Nov 12, 2016

Thanks for those changes @irfangul92! I'm going to test this just to make sure I didn't miss anything and will include it in the next release! 😍

@unnamedd
Copy link

unnamedd commented Mar 7, 2017

Hi @hsousa, do you have any intent to merge this pull request into master branch ?

@hsousa
Copy link
Owner

hsousa commented Mar 7, 2017

Sorry, yes! I've just been horrible at maintaining this... I'll try to push out a release this week with these changes!

Thanks again for this! ❤️

@unnamedd
Copy link

unnamedd commented Mar 7, 2017

Very nice @hsousa! Thank you for your quick response and for your beautiful library.

@hsousa hsousa merged commit 1d8c873 into hsousa:master Mar 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants