ComponentOne Xamarin.iOS Documentation
Controls / Input / Toggle Button / Quick Start: Change State and Customize the Control
In This Topic
    Quick Start: Change State and Customize the Control
    In This Topic

    This section describes adding the C1ToggleButton control to your portable or shared application and changing color of the control on the basis of change in state of the control.

    Complete the following steps to change color of the control on changing its state.

    Step 1: Initialize C1ToggleButton in code

    1. In the Solution Explorer, click MainStoryboard to open the storyboard editor.
    2. From the Toolbox under the Custom Components tab, drag the C1ToggleButton control onto the ViewController.
    3. In the Properties window, set the Name of the control as tb.
    4. Open the ViewController file from the Solution Explorer and replace its content with the code below to initialize C1ToggleButton control. This overrides the ViewDidLoad method of the View controller.
      C#
      Copy Code
      public override void ViewDidLoad()
      {
         base.ViewDidLoad();
      
         C1ToggleButton tb = new C1ToggleButton();
         if (tb.IsChecked == true)
         {
              tb.BackgroundColor = UIColor.Green;
         }
         else if (tb.IsChecked == false)
         {
              tb.BackgroundColor = UIColor.Red;
         }           
      }
      

      Back to Top

      Step 2: Run the Project

      Press F5 to run your application

      Back to Top