Support => NGUI 3 Support => Topic started by: fanling3 on March 20, 2014, 10:21:29 PM
Title: Disabling button inside tab content
Post by: fanling3 on March 20, 2014, 10:21:29 PM
Hi all, I have a Tab panel using UIToggle (basically the same as NGUI Example 13), and I have several UIButtons inside each tab. I want to disable the button after I click on it, so I have written a function using isEnabled = false and put it in onClick event of the buttons.
It looks cool when I click on the buttons, they turn grey, but when I switch to another tab and switch back. The buttons become blue color again, though I cannot hover them or click them. But they are in blue color. How to fix this? Thanks.
Title: Re: Disabling button inside tab content
Post by: ArenMook on March 21, 2014, 01:54:02 PM
Here's what I just tried.
1. Opened the Tabs example. 2. Dragged in the "Control - Simple Button" under "Content 1" object. 3. Added this script to it:
usingUnityEngine;
publicclass Test : MonoBehaviour
{
void OnClick ()
{
GetComponent<UIButton>().isEnabled=false;
}
}
4. Hit Play, clicked the button -- it became gray. 5. Switched to the second tab, then back to the first. The button is still gray.
Title: Re: Disabling button inside tab content
Post by: fanling3 on March 23, 2014, 09:17:56 PM
I tried the above but when I switched back to tab1 the simple button becomes bright again. I tried to print GetComponent<UIButton>().isEnabled and confirmed that it is false after I clicked it and switch back to tab1 from tab2, and the button cannot be clicked, however the button is still bright in color.
Cause the thing NGUI did for activating the tab content is just SetActive(true) to all game objects under the tab, I think the above script has nothing to do with the initial color of the button. When I click on tab2, the color of the simple button will change to normal state.
I am using NGUI 3.5.3
Title: Re: Disabling button inside tab content
Post by: ArenMook on March 24, 2014, 03:50:55 PM
I did the test with NGUI 3.5.5.
Title: Re: Disabling button inside tab content
Post by: fanling3 on March 24, 2014, 08:42:50 PM
I updated NGUI and it works without the above script. Seems the latest version fixed it already. Thanks.