Home:ALL Converter>Auto Layout in Navigation Controller with UISegmentedControl: good in iOS7, bad in iOS6

Auto Layout in Navigation Controller with UISegmentedControl: good in iOS7, bad in iOS6

Ask Time:2014-02-06T20:47:19         Author:Rainer Schwarze

Json Formatter

For a navigation controller I like to have a few controls placed in a view from top towards the bottom. I am using auto layout and added constraints, so that the views have a vertical gap to each other. This looks nice for iOS7 and iOS6 in a normal view controller, also for iOS7 in a navigation controller; but wrong in iOS6. The UISegmentedControl shows up wrong. See the screenshots.

It looks like the larger height of the UISegmentedControl is not taken into account for iOS6 view. Also it gets shifted out of place when switching from 3.5 inch to 4 inch screen.

Note that this only occurs in a navigation controller view. In the storyboard for the navigation controller I set Top Bar to "Opaque Navigation Bar". The upper button has a constraint "Top Space to Top Layout Guide". All other controls have a constraint "Top Space to ...." (control above them).

Are there any known fixes which I could apply?

What could be wrong? (I'm quite a newbie for auto layout.) Or is it just a bug which I have to work around somehow?


EDIT:

I tried placing the segmented control in an extra view, but that did not help either.

I could set a height constraint to the segmented control and that did help in a way. But this sets the same height to both iOS6 and iOS7 for the segmented control. My work around would now be to change/add the height constraint in code when the view loads and set a value depending on the iOS version. Are there other recommendations?


The screenshots:

In Navigation Controller, iOS6 view:

Shifted Layout in iOS6-View

In Navigation Controller, iOS7 view:

Nice Layout in iOS7


In a "normal" view controller, iOS6 view:

Nice Layout in iOS6-View

In a "normal" view controller, iOS7 view:

Nice Layout in iOS7

Author:Rainer Schwarze,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/21603430/auto-layout-in-navigation-controller-with-uisegmentedcontrol-good-in-ios7-bad
Sepehrom :

Select your button in interface builder, and in Attributes Inspector pane, set Type to Custom !",
2014-02-06T13:25:54
yy