一个UISegmentedControl对象是横向控制多个段,每个段作为一个独立的按钮运作。分段控制提供一个紧凑的手段,组合到一起的控制。
|
|
|
|
e.g.1234567UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"1",@"2",@"3"]];segmentedControl.frame = CGRectMake(0, 0, 150, 44);segmentedControl.tintColor = [UIColor redColor];segmentedControl.apportionsSegmentWidthsByContent = YES;segmentedControl.selectedSegmentIndex = 2;[segmentedControl addTarget:self action:@selector(clickItem:) forControlEvents:UIControlEventTouchUpInside];self.navigationItem.titleView = segmentedControl;