SelectedTintColor of Segment Control is not rounded corner on iOS 13

后端 未结 5 1270
迷失自我
迷失自我 2021-02-06 12:49

Rounded corner is working great on iOS 12 and below, but it\'s broken on iOS 13. I\'ve created a custom Segment control class.

Code:

cla         


        
5条回答
  •  梦毁少年i
    2021-02-06 13:03

    Make a custom class for segment

    class CustomSegmentedControl: UISegmentedControl {
    override func layoutSubviews() {
        super.layoutSubviews()
        layer.cornerRadius = self.bounds.size.height / 2.0
        layer.borderColor = use_your_custom_color
        layer.borderWidth = 1.0
        layer.masksToBounds = true
        clipsToBounds = true
        for i in 0...subviews.count - 1{
            if let subview = subviews[i] as? UIImageView{
                if i == self.selectedSegmentIndex {
                    subview.backgroundColor = use_your_custom_color
                }else{
                    subview.backgroundColor = .white
                }
            }
        }
    }}
    

    May be this will easy to use like this

       @IBOutlet weak var reminderSegmentControl: CustomSegmentedControl!
    

提交回复
热议问题