使UISwitch边框宽度更小

时间:2017-08-28 03:08:05

标签: ios swift uiswitch

您好我想让UISwitch borderWidth缩小,但看起来不正确。

我所做的一切都是 layer.borderWidth = 0.5

It looks like there is two layers. The border color is suppose to be gray, but for some reason black shows?

1 个答案:

答案 0 :(得分:2)

而不是使用storyboard尝试以编程方式自定义切换。尝试使用以下代码,就像更改一个参数一样,也必须调整开关的半径。希望它有所帮助

OnOffSwitch.layer.borderWidth = 1.0;
OnOffSwitch.layer.cornerRadius = 16.0;

enter image description here

OnOffSwitch.layer.borderWidth = 0.5;
OnOffSwitch.layer.cornerRadius = 17.0;

enter image description here