2016-11-11 39 views
0

我在navigationBar上有UISegmentedController。分段控制,用下面的代碼添加:如何製作導航欄的子視圖

@property (nonatomic) UISegmentedControl *segView; 
... 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    _segView = [[UISegmentedControl alloc] initWithItems:@[@"Seg1", @"Seg2"]]; 
    [_segView setSelectedSegmentIndex:0]; 
    [_segView addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 
    [self.navigationController.navigationBar addSubview:_segView]; 
} 

當我推到視圖navigationController,分段控制仍然存在,所以最近推視圖的標題將與分段控制重疊。

enter image description here

如何使分段控制被壓入堆棧與以往有何看法?

回答

1

而不是加UISegmentedControl作爲subViewnavigationBar設爲titleViewnavigationItem這樣。

self.navigationItem.titleView = _segView; 
+0

正是我所需要的。 :) –