Search code examples
ioscocoa-touchuiviewuikituisegmentedcontrol

How to change the corner radius of UISegmentedControl?


Is it possible to change the corner radius of UISegmentedControl? I have tried the following approach which we use to change a UIView's corner radius.

self.segmentedControl.layer.cornerRadius = 15.0;
self.segmentedControl.layer.masksToBounds = YES;

This did not work as you can see it only cuts off the UISegmentedControl's corner:

cut off corner


Solution

  • This should work:

    self.segmentedControl.layer.cornerRadius = 15.0;
    self.segmentedControl.layer.borderColor = [UIColor whiteColor].CGColor;
    self.segmentedControl.layer.borderWidth = 1.0f;
    self.segmentedControl.layer.masksToBounds = YES;
    

    You need to specify the border after setting cornerRadius.