Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl text programmatically

I have created a UISegmentedControl with two segments using the interface builder (from storyboard), but I would like to set the text of the two segments programmatically. I want to do this because I am using NSLocalizedString for all of my buttons, labels, titles etc. I create all the stuff in interface builder and then I add text programmatically. I have manage to make every item to work that way but I cannot find a way to add text to my UISegmentedControl.

Is there any way to do that? I ma trying to use the following but because the segmented control is already created in the interface builder it does not work.

[segmentedControl initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Title 1", @"Title 1"),NSLocalizedString(@"Title 2", @"Title 2"), nil]]; 

Thanks a lot

like image 533
user1015777 Avatar asked Mar 22 '12 00:03

user1015777


People also ask

How do you get the selected segment title in Swift?

Enter Swift as Language and choose Next. Go to the Storyboard and drag a Segmented Control to the top of the main view. Also drag a Label to the view and place it below the Segmented Control. Select the label and give it a text of First Segment selected.


1 Answers

[segmentedControl setTitle:<YourLocalizedString> forSegmentAtIndex:0]; 
like image 159
shabbirv Avatar answered Oct 13 '22 15:10

shabbirv