Uisegmentedcontrol Below Uinavigationbar in iOS 7

UISegmentedControl below UINavigationbar in iOS 7

It's a simple effect to accomplish.

First, place a segment in a toolbar. Place this toolbar right below the navigation bar. Set the delegate of the toolbar to your view controller, and return UIBarPositionTopAttached in positionForBar:. You can see in the store app, if you perform an interactive pop gesture, that the segment bar does not move the same as the navigation bar. That's because they are not the same bar.

Sample Image

Now to remove the hairline. The "hairline" is an UIImageView that is a subview of the navigation bar. You can find it and set it as hidden. This is what Apple does in their native calendar app, for example, as well as the store app. Remember to show it when the current view disappears. If you play a little with the Apple apps, you will see that the hairline is set to hidden on viewWillAppear: and set to shown in viewDidDisappear:.

To achieve the style of the search bar, just set the bar's searchBarStyle to UISearchBarStyleMinimal.

How to add the UISegmentedControl in UINavigationBar?

To put it in the navigationBar has a right left and title view for such things... accessed using....

self.navigationItem.titleView = mySegmentedControl

for future reference....

self.navigationItem.rightBarButtonItem
self.navigationItem.leftBarButtonItems // for adding an Array of items

To add it below the navigation view but have it static.. add it to the viewController.view... Are you using a UITableViewController? If so maybe switch to a UIViewController and add a tableView then your toolbarview as subviews to that self.view.

Add segmented control to navigation bar and keep title with buttons

I have tried solving your problem using another approach since using a navigation bar only didn't seem to work out (maybe it's because the AppStore app is using a private api but I'm not knowledgeable enough to tell for sure...)
Anyway I simply used a toolbar placed just underneath the navigation bar on which I added a segmented control, all inside a regular UIViewController.

This is what it looks like in Storyboard:
Storyboard

And this is the result in Simulator:

Simulator

Just be careful to offset the table view down to account for the vertical space used up by the toolbar.
Hope this helps!

UISegmentedControl inside title of UINavigationBar looks unformatted

To style a segmented control, set the segmentedControlStyle property to one of the following:

UISegmentedControlStylePlain
UISegmentedControlStyleBordered
UISegmentedControlStyleBar
UISegmentedControlStyleBezeled

For example:

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Info",@"Map"]];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
self.navigationItem.titleView = self.segmentedControl;

    
There's some relevant Q+As on here regarding styling segment controls:

  • Custom segment control
  • Remove rounded corner
  • Change font size
  • Change colour of selected segment

If you'd like to try a custom segmented control, check out all the available CocoaControls and CocoaPods.

UiSegmentedControl on NavigationBar below Title

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:
iOS Sample Image 28



Related Topics



Leave a reply



Submit