Warm tip: This article is reproduced from stackoverflow.com, please click
ios uikit cocoa-touch uiview uisegmentedcontrol

How to change the corner radius of UISegmentedControl?

发布于 2020-04-03 23:19:46

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. enter image description here

Thanks!

Questioner
wz366
Viewed
18
xi.lin 2016-02-14 00:44

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.