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
Fixed an issue where button's setTitle(string:state:) did not respond to a title change. #9
Conversation
… to a title change. The cause of the problem was the getAttributedString() method, which always returned the value .attributedText and ignored the value of .text;
I forgot to mension override method in PMSuperButton, which is self explanatory: override open func setTitle(_ title: String?, for state: UIControlState) {
// setTitle always sets attributed text
self.setAttributedTitle(getAttributedString(with: title, letterSpacing: letterSpacing), for: state)
} What do you think, is it ok always setting the attributed string for |
Ohh thanks for this fix. What happens if the user wants to set a custom attributed title? Did he lose all the changes? |
I tested your solution, but I think that this can be better:
This solution works on all cases that I tested and is more simple and elegant + in future can be added more IBInspectable variables that need use the setAttributedString override method. What do you think? |
In reality, this fixes not manage all the cases, for example, the color change and other adjustments on UIButton. I think we need to remove the letter spacing feature, at least for now. |
@codeido, I think we can solve this problem. Let's continue the discussion until we find the best solution. I will try to prepare another solution till the end of this week. |
Excellent @mixdesign, consider that everything that impacts the text needs to be "converted" in a NSAttributedString with this approach. |
Hey, @codeido It works well with various combinations of programmatically calling setTitle, setAttributedTitle, setTitleColor. I'm still testing it on my real project, just keep an eye by now. |
Hi, @codeido
Thanks for accepting my PR.
We have a problem in previous PR's implementation 😶:
Everythings works OK if the developer configures the button only through the storyboard.
But, if there is a need to change the title of the button programmatically, then a problem arises:
I fixed the issue.
Now we have a flexible function:
In the future PR with another attributed string features, we may create another common private function which will return
titleLabel's
NSMutableAttributedString with a single string parameter.Thanks!