How to programmatically configure a segment in a UISegmentControl?

I install UISegmentControl programmatically in my iPhone application. By default, it has 2 segments. In my code, I populate more than two segments. How to install this, any help?

Update

My question is how to add more than 2 tabs to a segmentController by code?

+4
source share
2 answers

First of all, segmented control in iOS belongs to the UISegmentedControl class, and not to NS ...

To create it with any number of segments you want, you can use the initWithItems: initialize method - pass an array of titles (NSStrings) or images for each segment. eg:.

 UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil]]; 

You can change your control insertSegmentWithImage:atIndex:animated: using the insertSegmentWithImage:atIndex:animated: insertSegmentWithTitle:atIndex:animated: or / and removeSegmentAtIndex:animated: .

You can find descriptions of these (and some more!) Methods in apple docs .

+19
source

Before editing, you actually talk about UISegmentedControl and set the selected program programmatically, you want to use the selectedSegmentIndex property (the documentation for which I am linked for you).

And to add additional segments, you can use insertSegmentWithTitle:atIndex:animated:

+3
source

Source: https://habr.com/ru/post/1384127/


All Articles