ios - iOS13 上 UIControlSegment 背景色不再透明

标签 ios swift uisegmentedcontrol uicolor ios13.2

我有一个 UISegmentedControl。 在iOS13之前它工作正常(我将backgroundColor和tintColor都设置为clear)。 但现在,我没有得到同样的结果。 我的 SegmentedControl 有一个浅灰色层。 我做了一些研究,但没有任何作用。 (我有同样的问题:https://forums.developer.apple.com/thread/123955)

之前的状态:

enter image description here

当前状态 - iOS13:

enter image description here

最佳答案

为了满足设计要求,我也面临这个问题。在我的例子中,SegmentedControl 背景颜色应该是白色或透明颜色,因为 View 的背景颜色也是白色。

所以我只是在 SegmentControl 背景中添加一个白色的 UImage,这个技巧对我有用。

if (@available(iOS 13.0, *)) {
   [segmentController setBackgroundImage:[UIImage imageNamed:@"someWhiteImage"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

虽然这不是一个完美的解决方案,但使用这个技巧可以满足我的要求。您现在还可以在背景中添加纯色背景图像。希望有人告诉我们正确的处理方法。

iOS 13 之前的必需设计

enter image description here

iOS 13之后

enter image description here

所以添加白色背景图像对我有用

关于ios - iOS13 上 UIControlSegment 背景色不再透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59212747/

相关文章:

iphone - 如何给uitoolbar添加分段控件

iphone - UISegmentedControl:以编程方式设置索引?

ios - Bar 分段控件在 iOS7 iphone 5s 真机上的 Toolbar 中有 padding

ios - 范围(0...4)和 substringWithRange?

swift - 电话号码的 NSURL 返回 nil

ios - 如何在 ios Swift 中将 JSON 转换为字符串?

swift - 将 @font-face 插入 WKWebView

ios - 如何在后台为 UIButton 设置渐变颜色?

ios - 防止 VoiceOver 导航 UICollectionView 的其他页面

ios - 警报 View : alertViewShouldEnableFirstOtherButton method can't detect subview textView