I'm setting UISegmentControl programmatically in my iPhone app. By default it has 2 segment. In my code I'm populating more than two segments. How do I set this, any help?
Update
My question is how do I put more than 2 tabs on segmentController by code?
First of all segmented control in iOS is of UISegmentedControl class, not NS...
To create it with any number of segments you want you can use initWithItems:
initialize method - pass array of titles (NSStrings) or images for each segments. e.g.:
UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil]];
Later you can change you control using insertSegmentWithImage:atIndex:animated:
, insertSegmentWithTitle:atIndex:animated:
or/and removeSegmentAtIndex:animated:
methods.
You can find descriptions on those (and some more!) methods in apple docs.
Before your edit, you were actually talking about UISegmentedControl and to set the selected one programatically, you want to use the selectedSegmentIndex
property (the documentation for which I've linked for you).
And to add in additional segments, you can use insertSegmentWithTitle:atIndex:animated:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With