Configure Segments (UISegmentedControl)

PDF for offline use
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

This recipe shows how to create a UISegmentedControl.

Recipe

On iOS 7 and above, the UISegmentedControl styling has been deprecated.

To create a UISegementedControl:

  1. Create and position the control:
var segmentControl = new UISegmentedControl();
segmentControl.Frame = new CGRect(20,20,280,40);
  1. Add the segments and select the default:
segmentControl.InsertSegment("One", 0, false);
segmentControl.InsertSegment("Two", 1, false);
segmentControl.SelectedSegment = 1;
  1. Optionally handle the ValueChanged event:
segmentControl.ValueChanged += (sender, e) => {
    var selectedSegmentId = (sender as UISegmentedControl).SelectedSegment;
    // do something with selectedSegmentId
};

Additional Information

You can create a UISegmentedControl in Xcode by dragging one to the design surface and setting the Segment count and properties in the Attributes Inspector.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.