如何禁用部分的uisegment控制?

以下是UISegmentedControl的代码

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: [UIImage imageNamed:@"down.png"], [UIImage imageNamed:@"dList.png"], nil]]; [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; segmentedControl.frame = CGRectMake(0, 0, 90, 65); segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; segmentedControl.momentary = YES; UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; [segmentedControl release]; self.navigationItem.rightBarButtonItem = segmentBarItem; [segmentBarItem release]; 

 - (void)segmentAction:(id)sender{ if([sender selectedSegmentIndex] == 0) { button.hidden=NO; } else { [self dListMethod ]; } } 

在if()部分,我想禁用selectedSegmentIndex==0并在button.hidden=YES时启用

使用setEnabled:forSegmentAtIndex:方法启用和禁用段。

 [segmentedControl setEnabled:NO forSegmentAtIndex:0]; 

如果你想禁用第一段。

对于那些可以对快速命令感兴趣的人:

Swift 2.3

 segmentedControl.setEnabled(false , forSegmentAtIndex: 0); 

Swift 3

 self.segmentedControl.setEnabled(false, forSegmentAt: 0);