How to set Segment in UISegmentControl programmatically?

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?

Answers


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.


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.