IOS中的分段控件的背景色

时间:2019-09-02 14:46:58

标签: colors background uisegmentedcontrol

我有一个分段控件,当被选中时,需要蓝色,而当未选中时,需要白色。取消选择颜色时,我面临设置颜色的问题,由于某种原因,它总是变成灰色。

这是它的样子:

enter image description here

蓝色边框实际上是具有某些边框颜色的UIView,并且在其中粘贴了分段控件。但是我不能更改灰色背景(应该是白色)。

我尝试做所有这一切:

    sc.selectedSegmentTintColor = UIColor.blue
    sc.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .body),NSAttributedString.Key.foregroundColor: UIColor.white], for: .selected)
    sc.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .body),NSAttributedString.Key.foregroundColor: UIColor.blue], for: .normal)
    sc.tintColor = .white
    sc.backgroundColor = .white
    sc.isOpaque =  true

没有成功。 :(

1 个答案:

答案 0 :(得分:0)

与背景色配合正常

self.backgroundColor = .red

在iOS 13中运行正常