Keeping a UIButton selected after a touch

后端 未结 9 1426
后悔当初
后悔当初 2020-11-27 11:41

After my user clicks a button, I\'d like that button to stay pushed during the time that I perform a network operation. When the network operation is complete, I want the bu

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 12:27

    Here is a C# / MonoTouch (Xamarin.iOS) implementation using approaches presented above. It assumes you have set the Highlighted image state already, and configures the selected and selected|highlighted states to use the same image.

    var selected = button.BackgroundImageForState(UIControlState.Highlighted);
    button.SetBackgroundImage(selected, UIControlState.Selected);
    button.SetBackgroundImage(selected, UIControlState.Selected | UIControlState.Highlighted);
    button.TouchUpInside += delegate
    {
        NSTimer.CreateScheduledTimer(TimeSpan.FromMilliseconds(0), delegate
        {
            button.Highlighted = true;
            NSTimer.CreateScheduledTimer(TimeSpan.FromMilliseconds(200), delegate
            {
                button.Highlighted = false;
            });
        });
    };
    

提交回复
热议问题