89

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

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Matt S.
  • 13,305
  • 15
  • 73
  • 129

4 Answers4

207

Objective-C

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

Swift:

let title = segment.titleForSegment(at: segment.selectedSegmentIndex)
Kevin Sylvestre
  • 37,288
  • 33
  • 152
  • 232
31
[segmentedControl titleForSegmentAtIndex:int];

For the current selected index

[segmentedControl titleForSegmentAtIndex:[segmentedControl selectedSegmentIndex]];
Brandon Bodnar
  • 8,202
  • 2
  • 36
  • 42
5

Swift 3:

segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)
Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
  • wondering why is this call giving me `extra argument 'at' in call` error in swift 3 with Xcode 8.3 – Umair Jun 06 '17 at 12:46
3

As this is the first Google result and we are now in the swift era:

Swift:

seg_ctrl.titleForSegmentAtIndex( seg_ctrl.selectedSegmentIndex)
John
  • 2,410
  • 1
  • 19
  • 33