iOS在导航栏上居中显示分段控件(UISegmentedControl)

    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];

 

你可能感兴趣的:(iOS在导航栏上居中显示分段控件(UISegmentedControl))