Hello,
ConfigurationUpdateHandler
is to respond changes to the button’s state, the button's state is Normal
, it doesn't change after you click the button (and you didn't set different config for different button state). Calling SetNeedsUpdateConfiguration
method will make the system call updateConfiguration
. The system calls this method automatically when the button’s state changes. Please see updateConfiguration | Apple Developer Documentation
If you want to change the configuration when you click the button, you can refer to the following code:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.MyButton.Tag = 1;//set tag for testing
this.MyButton.ConfigurationUpdateHandler += this.UpdateHandler;
this.MyButton.TouchUpInside += (s, a) =>
{
MyButton.Tag = MyButton.Tag ==1?0:1;// change tag when you click the button
};
}
private void UpdateHandler(UIButton button)
{
var config = UIButtonConfiguration.PlainButtonConfiguration;
config.Title = "test1";
config.BaseForegroundColor = UIColor.Green;
/* it's recommended to change the config according to the state*/
//switch (button.State)
//{
// case UIControlState.Normal:
// config.Title = "Normal"; //or"test1"
// config.BaseForegroundColor = UIColor.Purple;
// break;
// case UIControlState.Selected:
// config.Title = "Selected";
// config.BaseForegroundColor = UIColor.Yellow;
// break;
// case UIControlState.Disabled:
// config.Title = "Disabled";
// config.BaseForegroundColor = UIColor.LightGray;
// break;
//...and other states
// default:
// config.Title = "test1";
// config.BaseForegroundColor = UIColor.Green;
// break;
//}
if (button.Tag == 1)
{
config.Title = "test2";
config.BaseForegroundColor = UIColor.Red;
}
button.Configuration = config;
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.