如何在UISegmentedControl中获取段的文本值?
答案 0 :(得分:186)
目标-C
NSString *title = [segment titleForSegmentAtIndex:segment.selectedSegmentIndex];
夫特:
let title = segment.titleForSegment(at: segment.selectedSegmentIndex)
答案 1 :(得分:29)
[segmentedControl titleForSegmentAtIndex:int];
对于当前选定的索引
[segmentedControl titleForSegmentAtIndex:[segmentedControl selectedSegmentIndex]];
答案 2 :(得分:4)
斯威夫特3:
segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)
答案 3 :(得分:1)
@IBAction func segmentedControlAction(sender: AnyObject) {
if(segementControl.selectedSegmentIndex == 0)
{
print(segementControl.titleForSegmentAtIndex(0))
}
else if(segementControl.selectedSegmentIndex == 1)
{
print(segementControl.titleForSegmentAtIndex(1))
}
}