ios 从 UISegmentedControl 获取字符串值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2489517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:01:51 来源:igfitidea点击:
get string value from UISegmentedControl
提问by Matt S.
How can I get the text value of a segment in a UISegmentedControl?
如何在 UISegmentedControl 中获取段的文本值?
回答by Kevin Sylvestre
Objective-C
目标-C
NSString *title = [segment titleForSegmentAtIndex:segment.selectedSegmentIndex];
Swift:
迅速:
let title = segment.titleForSegment(at: segment.selectedSegmentIndex)
回答by Brandon Bodnar
[segmentedControl titleForSegmentAtIndex:int];
For the current selected index
对于当前选定的索引
[segmentedControl titleForSegmentAtIndex:[segmentedControl selectedSegmentIndex]];
回答by Ecnalyr
Swift 3:
斯威夫特 3:
segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)
回答by John
As this is the first Google result and we are now in the swift era:
由于这是第一个谷歌结果,我们现在处于 swift 时代:
Swift:
迅速:
seg_ctrl.titleForSegmentAtIndex( seg_ctrl.selectedSegmentIndex)
回答by shan
@IBAction func segmentedControlAction(sender: AnyObject) {
if(segementControl.selectedSegmentIndex == 0)
{
print(segementControl.titleForSegmentAtIndex(0))
}
else if(segementControl.selectedSegmentIndex == 1)
{
print(segementControl.titleForSegmentAtIndex(1))
}
}

