id | title | brief | sdk | |||||
---|---|---|---|---|---|---|---|---|
13B08892-8DDC-CDDE-63A1-9994E1569249 |
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
:
- Create and position the control:
var segmentControl = new UISegmentedControl();
segmentControl.Frame = new CGRect(20,20,280,40);
- Add the segments and select the default:
segmentControl.InsertSegment("One", 0, false);
segmentControl.InsertSegment("Two", 1, false);
segmentControl.SelectedSegment = 1;
- Optionally handle the
ValueChanged
event:
segmentControl.ValueChanged += (sender, e) => {
var selectedSegmentId = (sender as UISegmentedControl).SelectedSegment;
// do something with selectedSegmentId
};
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.