在iOS 8中更改UISegmentedControl的边框宽度

时间:2014-10-28 15:40:27

标签: ios swift ios8 uisegmentedcontrol

如何在iOS 8中更改UISegmentedControl的边框宽度?目前,边框宽度为2px,我想将其设置为1px。设置CALayer的边框宽度似乎不起作用。我似乎无法在任何地方找到任何相关信息。

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:3)

适用于iOS 8.1

   _segmentedControl.layer.borderWidth = 2;

答案 1 :(得分:2)

我建议您根据需要使用自定义分割器图像:

[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal                   rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
[mySegmentedControl setDividerImage:image2 forLeftSegmentState:UIControlStateSelected                   rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
[mySegmentedControl setDividerImage:image3 forLeftSegmentState:UIControlStateNormal                   rightSegmentState:UIControlStateSelected barMetrics:barMetrics];

查看此处的文档https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UISegmentedControl.html