iOS 13对UISegmentedControl进行了一些更改,设置backgroundColor为.white时,无论怎么设置它总是显示了一个有点灰色的,即使没有tintColor或应用类似的设置。将设置backgroundColor为其他颜色可显示相同的行为,但用白色最为明显。实在不知道是为什么。目前找到的解决办法如下:
func fixBackgroundSegmentControl( _ segmentControl: UISegmentedControl){
if #available(iOS 13.0, *) {
//just to be sure it is full loaded
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
for i in 0...(segmentControl.numberOfSegments-1) {
let backgroundSegmentView = segmentControl.subviews[i]
//it is not enogh changing the background color. It has some kind of shadow layer
backgroundSegmentView.isHidden = true
}
}
}
}
希望能帮助到你!