I created a toolbar with a segmented control inside, then made the segmented control 320 wide. I then set flexible layout guides on each side to force the segmented control into the center. This looks fine in portrait, but the segmented control will not stretch out for landscape.
Portrait (includes IB setup and simulator)
Landscape (also includes IB setup and simulator)
It seems like the app store has a segmented control that is set to a certain width and then the view isn't allowed to rotate. I understand you would like the segmented control to change width with the layout, but unfortunately that's not possible with auto layout at the moment.
My suggestion would be, if you really wanted the segmented control to change width with rotation would be to programmatically set the width when the device rotates to landscape.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
//set segmented control to landscape
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
//set segmented control to portrait width
}
}
One more thing, if you do end up using this device rotation stuff, you'll still need those flexible spacers in IB to keep your segmented control centered in the toolbar
UIView
is that there's so much customization needed to make it behave like aUIToolbar
. But I guess it's easier than handling the sizing manually. – Kopple