以下是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
答案 0 :(得分:142)
使用setEnabled:forSegmentAtIndex:
方法启用和禁用细分。
[segmentedControl setEnabled:NO forSegmentAtIndex:0];
如果要禁用第一个段。
答案 1 :(得分:17)
对于那些对 swift 命令感兴趣的人:
Swift 2.3
segmentedControl.setEnabled(false , forSegmentAtIndex: 0);
Swift 3
self.segmentedControl.setEnabled(false, forSegmentAt: 0);