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

Breaks normal usage of setTitleColor #3

Closed
3lvis opened this issue May 23, 2015 · 9 comments
Closed

Breaks normal usage of setTitleColor #3

3lvis opened this issue May 23, 2015 · 9 comments
Assignees

Comments

@3lvis
Copy link
Collaborator

3lvis commented May 23, 2015

  • Install the category via CocoaPods
  • Open a ViewController
  • Add a button
  • Set the outlet
  • Change color in viewDidLoad
[self.superAwesomeButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];

Sample project:
https://github.com/uzegonemad/hyperoslo-form-uibutton-issues

@uzegonemad
Copy link

Hey @3lvis, this is primarily in response to https://github.com/hyperoslo/Form/issues/415.

While this workaround would most likely work, I've got a good 20-30 buttons that break when this category is in use. Most of the buttons have images which darken on highlight, so the preferred fix would be something that doesn't require modifying core functionality.

@3lvis
Copy link
Collaborator Author

3lvis commented May 23, 2015

@uzegonemad Definitely! I agree, it should just work.

@3lvis 3lvis self-assigned this May 22, 2016
@LightMan
Copy link

LightMan commented May 24, 2016

Hi Elvis, me again.

I am facing this issue, I changed your code, so the first time the button is clicked it takes automatically the normal and highlighted title color from the button. So there is no need to establish by code the title color. And buttons in xibs/storyboards with a custom highlight text colors will work ok with this.

Have a look and tell me what you think.

- (void)setHighlighted:(BOOL)highlighted
{
    [super setHighlighted:highlighted];

    if (self.highlightedTitleColor == nil){
        self.highlightedTitleColor = [self titleColorForState:UIControlStateHighlighted];
    }

    if (self.titleColor == nil){
        self.titleColor = [self titleColorForState:UIControlStateNormal];
    }

    if (self.highlightedTitleColor && self.titleColor) {
        UIColor *titleColor = self.highlighted ? self.highlightedTitleColor : self.titleColor;
        [self setTitleColor:titleColor forState:UIControlStateNormal];
        [self setTitleColor:titleColor forState:UIControlStateHighlighted];
        [self setTitleColor:titleColor forState:UIControlStateSelected];
    }

    if (self.highlightedBackgroundColor && self.originalColor) {
        self.backgroundColor = self.highlighted ? self.highlightedBackgroundColor : self.originalColor;
    }
}

@3lvis
Copy link
Collaborator Author

3lvis commented May 24, 2016

@LightMan Wow, David. You came to save the day. This definitely fixes the issue. I'll push an update.

Thanks a lot!

@skarctop
Copy link

all button will be gray after click, but i don't want that, this is still not well

@skarctop
Copy link

it affect all buttons - not just those implemented in Form. why do you use category

@3lvis
Copy link
Collaborator Author

3lvis commented Sep 14, 2016

@skarctop It's a category, and should only affect your buttons if you use any of the added attributes.

screen shot 2016-09-14 at 07 40 07

@LightMan
Copy link

Well, I had to change - (void)setHighlighted:(BOOL)highlighted method because it was affecting all buttons in my app. By default when buttons are pressed they change to the highlighted colour, so I tried to "patch" this method to adopt the default behaviour if the buttons were not using the FORM library. But I guess if you don't want the default behaviour for buttons, grey colour when pressed, this will not work.

IMHO FORM should not use categories that override the default behaviour or any SDK's methods. Anyway, since I used this library I will gladly help to whatever changes are needed, but I think this will imply a decent change. @3lvis what do you think?

@3lvis
Copy link
Collaborator Author

3lvis commented Sep 14, 2016

@LightMan Makes sense :) Go for it.

This issue was closed.
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

No branches or pull requests

4 participants