UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
segmentedControl.tintColor = [UIColor orangeColor]; //渲染色彩
[segmentedControl insertSegmentWithTitle:@"专家介绍"atIndex:0 animated:NO];
[segmentedControl insertSegmentWithTitle:@"问题解答"atIndex:1 animated:NO];
segmentedControl.selectedSegmentIndex = 0; //初始指定第0个选中
// [segmentedControl addTarget:self action:@selector(controlPressed:)
// forControlEvents:UIControlEventValueChanged];
// 第一种方法
// [self.navigationItem setTitleView:segmentedControl];
// 第二种方法
[self.navigationController.navigationBar.topItem setTitleView:segmentedControl];
时间: 2024-10-11 17:53:10