Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl without rounded corner?

Is there a way of get rid of UISegmentedControl's rounded corners or it is the default behavior?

like image 319
Robert Childan Avatar asked Dec 02 '09 16:12

Robert Childan


3 Answers

There's something really easy that you can do to rid yourself of the rounded junk on the UISegmentedControl ... change the style to "7". I'm not joking. I just figured this out:

    // Magic number ... (it's cheating, but it works)
  mySegmentedBar.segmentedControlStyle = 7;  

This is the same control style they use in the UISearchBar's scope bar, like this:

Search Bar With Scope

But if someone only wants the scope bar, without the search, they're usually stuck with UISegmentedControl junk like this (with rounded corners):

BarStyle

Or worse, this...

BezeledStyle

Thankfully, by switching to bar style "7", we get the exact look of the stop bar, without all the subclassing and drawRect hackery:

enter image description here

like image 158
Greg Combs Avatar answered Nov 20 '22 11:11

Greg Combs


No, there is no API that gives you control over the layout of the segments.

You could probably try looking into the UISegmentedControl's view.subviews and try to change them according to your needs. But from personal experience I would not advice that. If Apple changed their order in the future your app will probably crash. The easiest thing to do is to create custom UIButtons that behave as toggle-buttons and control them like a UISegmentedControls (for toggle-buttons see How to use a UIButton as a toggle switch).

like image 34
Dimitris Avatar answered Nov 20 '22 09:11

Dimitris


If you wanted a different look you could just subclass it and do your own drawing in -drawRect:. See the Quartz 2D Programming Guide for reference on drawing with Quartz/Core Graphics.

like image 1
Daniel Tull Avatar answered Nov 20 '22 10:11

Daniel Tull