问题描述
iOS 13对UISegmentedControl进行了一些更改,包括在切换所选段时非常漂亮的动画.但是,我注意到它没有正确显示backgroundColor
属性,它似乎总是有些淡淡.
iOS 13 introduced some changes to the UISegmentedControl including a really nice animation when switching the selected segment. However I'm noticing that it's not displaying the backgroundColor
property correctly, it always seems to have a bit of a tint to it.
我见过一些回答如何设置selectedSegmentTintColor
的问题,但是我正在努力设置backgroundColor
说.white
,无论我做什么,它总是显示为灰色即使没有应用tintColor
或类似设置.将backgroundColor
设置为其他颜色可显示相同的行为,但最明显的是白色.更令人迷惑的是,虽然这种差异在iOS 13模拟器和运行iOS 13的物理设备上均会显示,但视觉调试器(在XCode 11 GM2中)却没有显示出这种差异!
I've seen questions that answer how to set the selectedSegmentTintColor
and such but I'm struggling to set the backgroundColor
to say .white
, no matter what I do it always shows up a bit of a gray even though there's no tintColor
or similar setting applied. Setting the backgroundColor
to other colors shows the same behavior but its most obvious with white. Adding to the mystery is that while this difference shows up on both iOS 13 simulators and a physical device running iOS 13, the visual debugger (in XCode 11 GM2) does not show this difference!
以下是一些屏幕截图,显示了即使UISegmentedControl
的backgroundColor
设置为与它后面显示的视图的backgroundColor
相同,它们也略有不同.
Here's a couple screenshots showing that even though the backgroundColor
of the UISegmentedControl
is set to the same as the backgroundColor
of the view shown behind it they are slightly different.
运行iOS 13的设备(白色backgroundColor)
Device running iOS 13 (white backgroundColor)
Visual Debugger中显示的相同视图/代码(白色backgroundColor)
Same view/code shown in Visual Debugger (white backgroundColor)
运行iOS 13的设备(蓝色backgroundColor)
Device running iOS 13 (blue backgroundColor)
我已尝试按照本SO帖子中的建议应用backgroundImage
的建议: UISegmentedControl iOS 13清除了颜色,但最终将样式恢复为在iOS 12中的外观,并且失去了漂亮的动画.
I've tried the suggestion of applying a backgroundImage
as suggested in this SO post: UISegmentedControl iOS 13 clear color but that ends up reverting the style back to how it looked in iOS 12 and you lose the nice animation as well.
任何指导或建议,我们将不胜感激!我还向Apple提交了错误报告,请查看是否有任何错误.
Any guidance or suggestions is greatly appreciated! I've also filed a bug report with Apple, will see if anything comes of that.
推荐答案
我遇到了同样的问题,没有解决之道.所以我做了这个小的解决方法.我不喜欢它,也不为它感到骄傲,但是它有效.
I have the same issue and there is no cool way to resolve it. So I did this small workaround. I dont like it and I am not proud of it, but it works.
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 13中将UISegmentedControl的backgroundColor设置为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!