Skip to content

Conversation

@natanrolnik
Copy link
Contributor

When initializing a TORoundedButton in the following way:

let button = RoundedButton(text: "I agree")
button.tintColor = UIColor.appPurple
button.textColor = .white
button.backgroundColor = .white
button.cornerRadius = 4

This is the result:

RoundedButton

Tapping on the button makes this glitch go away, because self.titleLabel.backgroundColor = self.isTapped ? [UIColor clearColor] : self.tintColor; is called.

This PR sets the titleLabel's backgroundColor on layoutSubviews to avoid this bug.

@TimOliver
Copy link
Owner

Thanks for the PR @natanrolnik!

Hmm, I think I actually had that sort of code set previously, however, it was causing issues with the interactive animation.

Can you try tapping down on the button, sliding your finger off, and then quickly back on again, and see if it flickers?

It definitely looks like I forgot to update the UILabel background color at some point. It's usually best to try and avoid setting in layoutSubviews as much as possible since it can get called multiple times inside an animation block.

@natanrolnik
Copy link
Contributor Author

Makes sense. I'll think about it - maybe it should be set whenever tintColorDidChange is called instead? That should solve this issue as well.

@natanrolnik natanrolnik changed the title Set titleLabel's backgroundColor on layoutSubviews Set titleLabel's backgroundColor on tintColorDidChange May 14, 2019
@natanrolnik
Copy link
Contributor Author

Ok @TimOliver - I've moved the line to tintColorDidChange which seems to be a better fit, in this case, considering the animations you mentioned.

I've tested and no flickering happens.

I've updated the PR.

@natanrolnik natanrolnik reopened this May 14, 2019
@natanrolnik
Copy link
Contributor Author

I made a small mistake related to indenting and empty lines - this is why you see force-pushes. It's good to merge now.

@TimOliver
Copy link
Owner

Awesome! Looks perfect to me! Thank you so much for doing that! :D

@TimOliver TimOliver merged commit fdb3401 into TimOliver:master May 15, 2019
@natanrolnik
Copy link
Contributor Author

Great!

Sent with GitHawk

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.

2 participants