将UISegmentedControl添加到导航控制器工具栏是否是一种异端?
我在考虑这段代码:
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];
我已经尝试过这段代码,并且看起来没有选中它们.
这是正确的方法吗?
谢谢.
最佳答案 这很可能是因为你的tintColor是黑色的.更改颜色,您应该看到所选的部分被反射.