首页 > 解决方案 > UISegmentedControl iOS 13 SelectedTint 默认颜色

问题描述

我想将默认值SelectedTintColorUISegmentControl另一个视图匹配,但我无法从属性检查器中提供的默认系统*颜色中找到匹配的颜色。

背景似乎是,.quaternarySystemFill但在明暗模式下都没有与所选颜色相匹配的颜色。

即使以这种方式设置颜色也不起作用,因为.selectedSegmentTintColor返回nil

label.backgroundColor = segmentedControl.selectedSegmentTintColor

有谁知道正确的颜色或者我需要使用自定义颜色吗?

编辑: UISegmentedControl_light UISegmentedControl_dark

编辑2: 目前这条线有效,但也许有更好的方法?

label.backgroundColor = label.traitCollection.userInterfaceStyle == .light ? .white : .tertiaryLabel

标签: swiftios13xcode11

解决方案


根据我对您问题的理解,您想更改与 UISegmentControl 色调相同的背景颜色。你需要做的只是使用这个:

label.backgroundColor = segmentedControl.tintColor 

希望对你有帮助


推荐阅读