Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

id title brief sdk
Configure Segments (UISegmentedControl)
This recipe shows how to create a UISegmentedControl.


ℹ️ Note: 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.