Search code examples
iosxcodeiphone-5

Change style of Segmented Control in code


I'm developing an app, and to make use of the extra space in the iPhone 5 screen, I would like to change the style of this UISegmentedControl. So, this involve two parts. First, detect in code if it's an iPhone 5 and then change the style.

In the 3.5" it will be this style

bar

And in the 4" this.

plain


Solution

  • Check the size of the screen using [[UIScreen mainScreen] bounds]. If bounds.size.height is bigger than some number (you decide what that would be) then set the segmented control's segmentedControlStyle property. For larger height you want UISegmentedControlStylePlain. For other, you want UISegmentedControlStyleBar.