SelectedTintColor of Segment Control is not rounded corner on iOS 13

后端 未结 5 1347
迷失自我
迷失自我 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条回答
  •  情书的邮戳
    2021-02-06 13:10

    I was facing the same issue on iOS 13. Then I dug into its view hierarchy then I found it has multiple subviews. So I made a trick for iOS 13. You have to do following changes for iOS 13 -

    1. ChangeselectedSegmentTintColor to Clear - self.selectedSegmentTintColor = .clear
    2. Add following code snippet inside layoutSubviews -

      for i in 0...subviews.count - 1{
      
              if let subview = subviews[i] as? UIImageView{
      
                  if i == self.selectedSegmentIndex {
      
                      subview.backgroundColor = UIColor(red: 170.0/255.0, green: 170.0/255.0, blue: 170.0/255.0, alpha: 1.0)
      
                  }else{
      
                      subview.backgroundColor = .clear
                  }
      
              }
          }
      

    I hope it will help you.

提交回复
热议问题