get string value from UISegmentedControl

Matt S. picture Matt S. · Mar 22, 2010 · Viewed 54.6k times · Source

How can I get the text value of a segment in a UISegmentedControl?

Answer

Kevin Sylvestre picture Kevin Sylvestre · Mar 22, 2010

Objective-C

NSString *title = [segment titleForSegmentAtIndex:segment.selectedSegmentIndex];

Swift:

let title = segment.titleForSegment(at: segment.selectedSegmentIndex)