UISegmentedControl with square corners

Joseph picture Joseph · Oct 12, 2011 · Viewed 19.9k times · Source

I would like to modify UISegmentedControl with a subclass to remove the rounded corners. I can't seem to set the cornerRadius. Making the SegmentedControl wider than the screen (and therefor "chop" off the corners) is not an option since I have 4 or 5 segments and they would then vary in size.

Is there a way to do this?

Thanks

Answer

swathy krishnan picture swathy krishnan · Feb 25, 2015

To make the corner square use the following code:

segmentContrl.layer.borderColor=*anycolor*.CGColor;
segmentContrl.layer.cornerRadius = 0.0;
segmentContrl.layer.borderWidth = 1.5f;