Skip to content

iOS UIButton backgroundColor does not respond to color changes #9523

Closed

Description

@rob4226

I have found that after a Button is created on iOS, it is not possible to change the backgroundColor of it. It doesn't change if you change the CSS class nor does accessing the background color like btn.backgroundColor = new Color('blue') The below only works on Android, where as on iOS the button background color does not change after it is first set:

const btn1 = new Button();
const btn2 = new Button();

let toggle = true;

// Background color doesn't change after it's created
btn1.on("tap", (_args) => {
  if (toggle) {
    btn1.color = new Color("red");
    btn1.backgroundColor = new Color("blue");
    toggle = false;
  } else {
    btn2.color = new Color("yellow");
    btn2.backgroundColor = new Color("black");
    toggle = true;
  }
});

stackLayout.addChild(btn1);
stackLayout.addChild(btn1);
}

I have had tons of issues on iOS when changing between dark and light themes while the app is running especially with buttons not responding to color changes and I think this might be the culprit. It appears that the backgroundColor property is not implemented on the iOS Button view.

I have made a PR to fix this in @nativescript/core.

Activity

  1. NathanWalker commented on Aug 24, 2021

    @NathanWalker
    Contributor

    @rob4226 thank you, possible to post a PR of the change? Looks like just a reference to a fork at moment. If post as a PR we can merge out to the next tag and it will be included in the 8.1 release soon.

  2. rob4226 commented on Aug 24, 2021

    @rob4226
    ContributorAuthor

    @NathanWalker Yes, I was just running some more tests on it, but it looks good. It's PR #9524.

    Also, I created a new branch using @nativescript/core@7.3.0 and made the necessary changes to fix v7 (new branch in fork based on 7.3.0). I have a couple projects still stuck on 7 so would it be possible to also release a v7.3.1 with this fix? If you already have a branch for v7 fixes please let me know and I will base the commit on that instead of a new branch. I couldn't find a tag for v7.3.0 but I went through the changelog and commits and found it to be 7847c2f Thanks.

  3. NathanWalker commented on Aug 24, 2021

    @NathanWalker
    Contributor

    Sure thing we could do that, much appreciated 🤗

  4. added a commit that references this issue on Aug 24, 2021
    c3cadc7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions