8

I want to add a segment controller to the navigation bar not as the title, but like this: enter image description here

How can I do that?

Eli_Rozen
  • 1,301
  • 4
  • 20
  • 31

2 Answers2

2

The problem is that it looks like this uses the navigation bar's title, which is actually in the same place as where you want your segmented control to go. Instead, you need to add a "prompt" to the navigation bar to increase the height of the bar, and add the prompt text above the content area of the bar.

This can be done purely in Interface Builder as illustrated by the screenshot below, or programmatically using the following code:

[self.navigationController.navigationItem setPrompt:@"some prompt text"];

enter image description here

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • 8
    But what about "Done" button? :) – Eli_Rozen Aug 26 '13 at 03:36
  • I can't get this to work in code (iOS 7, Storyboards)—do you put that line in viewDidLoad, viewWillAppear, ...? In the containing view controller, the contained view controller...? – Robert Atkins Apr 24 '14 at 11:54
0

I've had to do the same and simply added the segmented control inside a view added under the navigationbar bottom.

Bruno Gama
  • 120
  • 1
  • 8