本文介绍了iPhone-将UISegmentedControl添加到导航控制器工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将UISegmentedControl添加到导航控制器工具栏是否是一个异端?
Is this an heresy to add a UISegmentedControl to a navigation Controller Toolbar?
我正在考虑以下代码:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[NSString stringWithString:NSLocalizedString(@"One", @"")],
[NSString stringWithString:NSLocalizedString(@"Two", @"")],
[NSString stringWithString:NSLocalizedString(@"Three", @"")],
[NSString stringWithString:NSLocalizedString(@"Four", @"")],
nil]];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor = [UIColor blackColor];
[segmentedControl setSelectedSegmentIndex:0];
[segmentedControl addTarget:self action:@selector(changeSegment:)
forControlEvents:UIControlEventValueChanged];
[segmentedControl setFrame:[self.navigationController.toolbar bounds]];
[self.navigationController.toolbar addSubview:segmentedControl];
[segmentedControl release];
我已经尝试过此代码,并且触摸这些段似乎没有选中该段.
I have tried this code and the segments don't appear to be selected with I touch them.
这是正确的方法吗?
谢谢.
推荐答案
这很可能是由于您的tintColor是黑色的.更改颜色,您应该可以看到所选的片段.
This is most likely due to your tintColor being black. Change the color and you should see the selected segment reflected.
这篇关于iPhone-将UISegmentedControl添加到导航控制器工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!