最近忙着搭建页面,昨天网上做选址界面的时候,需要在NavigationBar的title位置放一个UISegmentControl,
于是学习了一下怎样处理,现在学会了与大家分享,放什么控件都行,只要是UIView的子类~
万变不离其宗~
UISegmentedControl *segmentControl = [[UISegmentedControl alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
segmentControl.tintColor = [UIColor whiteColor];
[segmentControl insertSegmentWithTitle:@"按地市" atIndex:0 animated:YES];
[segmentControl insertSegmentWithTitle:@"按拼音" atIndex:1 animated:YES];
segmentControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentControl;