Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UiSegmentedControl on NavigationBar below Title

I am new on iOS Development and during my works for an app I am building right now some doubts have appeared to me. I am trying to build a Screen that will be compounded by multiple ViewControllers, but on the NavigationBar I would like to have a UiSegmentedControl above the Title, something like a Scope Bar to control the navigation between the children ViewController. I wanted to build something similar to what we have on HealthKit Dashboard:

enter image description here.

What kind of approach do you suggest to do that? I understand that some questions have already been done about it, but after a long research I have not got to a conclusion.

During my research I noticed that a UISearchBar on the NavigationBar ( to build the Scope Bar ) is only possible for UITableViewControllers, Am I right? So I think that can not be an approach.

My next idea was to use a UISegmentedControl placed manually below the NavigationBar and then use the Containment Api to change to the different ViewControllers for this Screen. The problem here, is I will have to duplicate the UISegmentedControl on all children ViewControllers. Is there any way to not have to duplicate that?

Another approach I tried was doing my own titleView for the NavigationBar with a NavigationBar and a UISegmentedControl below. I don’t like this idea, neither it went well trying to replicate the NavigationBar.

Finally, another approach I thought was using a UIPageViewController. Although this approach sounds a good idea to me, I think I will also have to duplicate the UISegmentedControl.

In the end I think the best solution is to have a UISegmentControl on the NavigationBar, but I am not seeing how to implement this.

What do you think is the best approach to accomplish my ideia? I thought that it would be easy because it is a pattern I see in many apps. Any suggestions?

I am doing this on XCode 6.1.1 using Swift for iOS 8.

Thanks a lot for your help.

like image 399
jantunes Avatar asked Dec 20 '14 19:12

jantunes


1 Answers

You can get this effect by adding the segment as the title view and setting your desired prompt. In interface builder it looks like this: enter image description here

like image 92
Ian Avatar answered Oct 01 '22 07:10

Ian