How to change background color of UIButton in Monotouch

后端 未结 3 344
借酒劲吻你
借酒劲吻你 2020-12-22 02:20

I am newbie to Monotouch and have added the following code to my SingleViewApplication. And you can see my controller code below, where I am trying to change the background

3条回答
  •  眼角桃花
    2020-12-22 02:34

    I am also face this problem but i solve this issue hope this code is help you

    public static class SwapUIButtonColor
    {
        #region prop
        public static UIButton PreviousButton {
        get
        {
            return _previousButton
        }
        set
        {
            _previousButton = value;
        }
    }
    public static UIButton CurrentButton 
    {
        get
        {
            return _currentButton;
        }
        set
        {
            _currentButton = value;
        }
    }
    public static bool SwapColor (UIButton sender, bool isPrevBakGraound)
    {
        if (isPrevBakGraound == false)
        {
            InitApplyColorBorder (sender);
            SwapUIButtonColor.PreviousButton = sender;
            return true;
        }
        else
        {
            if (SwapUIButtonColor.PreviousButton != sender)
            {
                InitApplyColorBorder (sender);
                SwapUIButtonColor.CurrentButton = PreviousButton;
                PreviousButton = sender;
                SwapUIButtonColor.CurrentButton.Layer.BorderColor = (UIColor.Black).CGColor;
                SwapUIButtonColor.CurrentButton.Layer.BorderWidth = 0f;
                SwapUIButtonColor.CurrentButton.Layer.CornerRadius = 0f;    
            }
            else if (SwapUIButtonColor.PreviousButton == sender)
            {
                InitApplyColorBorder (sender);
                SwapUIButtonColor.PreviousButton = sender;  
            }
            return true;
        }
    }
    static void InitApplyColorBorder (UIButton sender)
    {
        sender.Layer.BorderColor = (UIColor.Red).CGColor;
        sender.Layer.BorderWidth = 1.0f;
        sender.Layer.CornerRadius = 10f;
    }
    

    Also from ViewDidload Method Call this above method on UIButton Click events

    private bool isPrevBakGraound = false;  
    isPrevBakGraound = SwapUIButtonColor.SwapColor (btnReset, isPrevBakGraound);
    

提交回复
热议问题