简体   繁体   English

iOS 13-UISegmentedControl-如何更改selectedSegment的角半径?

[英]iOS 13 - UISegmentedControl - How do you change the corner radius of the selectedSegment?

In regards to iOS 13 updates on UISegmentedControl: 关于UISegmentedControl上的iOS 13更新:

This custom UISegmentedControl class rounds the corners of the segmented control. 这个自定义的UISegmentedControl类使分段控件的角落变得圆满。 But it does not round the corners of the selected control (that still has the default corner radius). 但是它不会使选定控件的角变圆(仍然具有默认的角半径)。 This makes it look weird, especially when you have a border on the segmented control: 这使它看起来很奇怪,尤其是在分段控件上有边框时:

class SegmentedControl: UISegmentedControl {
      override func layoutSubviews() {
        super.layoutSubviews()

        layer.cornerRadius = 20
        layer.masksToBounds = true
        clipsToBounds = true
     }
}

Before you could just do segmentedControl.layer.cornerRadius = 20 and it would apply to everything but you can't do that anymore. 在您只能执行segmentedControl.layer.cornerRadius = 20 ,它将适用于所有内容,但您将无法再执行此操作。

Has anyone figured this out? 有人知道吗?

UISegmentControl doesn't expose internal subviews for any changes. UISegmentControl不会公开内部子视图的任何更改。 You can use custom segment control that will provide more options for customisation. 您可以使用自定义细分控件,该控件将提供更多自定义选项。 That's an example from first suggestions results of search on Github: https://github.com/sasojadrovski/SJFluidSegmentedControl 这是来自Github上搜索的第一个建议结果的示例: https : //github.com/sasojadrovski/SJFluidSegmentedControl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM