从UISegmentedControl获取string值

如何获得UISegmentedControl中的段的文本值?

Objective-C的

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

迅速:

 let title: String = segment.titleForSegmentAtIndex(segment.selectedSegmentIndex) 
 [segmentedControl titleForSegmentAtIndex:int]; 

对于当前选定的索引

 [segmentedControl titleForSegmentAtIndex:[segmentedControl selectedSegmentIndex]]; 

因为这是谷歌的第一个结果,我们现在正处于迅速的时代:

迅速:

 seg_ctrl.titleForSegmentAtIndex( seg_ctrl.selectedSegmentIndex) 

Swift 3:

 segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex) 
 @IBAction func segmentedControlAction(sender: AnyObject) { if(segementControl.selectedSegmentIndex == 0) { print(segementControl.titleForSegmentAtIndex(0)) } else if(segementControl.selectedSegmentIndex == 1) { print(segementControl.titleForSegmentAtIndex(1)) } }