gpt4 book ai didi

ios - 如何在 iOS 13 中将 UISegmentedControl 的背景颜色设置为白色

转载 作者:行者123 更新时间:2023-12-02 03:46:08 35 4
gpt4 key购买 nike

iOS 13 对 UISegmentedControl 进行了一些更改,包括切换所选片段时的非常漂亮的动画。但是我注意到它没有正确显示 backgroundColor 属性,它似乎总是有一点色调。

我见过回答如何设置 selectedSegmentTintColor 等问题,但我很难将 backgroundColor 设置为 .white >,无论我做什么,即使没有应用 tintColor 或类似的设置,它总是显示出一点灰色。将 backgroundColor 设置为其他颜色会显示相同的行为,但白色最为明显。更神秘的是,虽然这种差异在 iOS 13 模拟器和运行 iOS 13 的物理设备上都显示出来,但可视化调试器(在 XCode 11 GM2 中)却没有显示这种差异!

这里有几个屏幕截图,显示即使 UISegmentedControlbackgroundColor 设置为与后面显示的 View 的 backgroundColor 相同它们略有不同。

运行 iOS 13 的设备(白色背景颜色) enter image description here

可视化调试器中显示的相同 View /代码(白色背景颜色) enter image description here

运行 iOS 13 的设备(蓝色背景颜色) enter image description here

我已经尝试了按照此 SO 帖子中的建议应用 backgroundImage 的建议:UISegmentedControl iOS 13 clear color但这最终会将样式恢复到 iOS 12 中的样子,并且你也会失去漂亮的动画。

非常感谢任何指导或建议!我还向 Apple 提交了错误报告,看看是否会产生任何结果。

最佳答案

我也有同样的问题,但没有很好的方法来解决它。所以我做了这个小解决方法。我不喜欢它,也不为此感到自豪,但它确实有效。

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
}
}
}
}

关于ios - 如何在 iOS 13 中将 UISegmentedControl 的背景颜色设置为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58105920/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com