【问题标题】:Background color for segmented control in IOSIOS中分段控制的背景颜色
【发布时间】:2019-09-02 14:46:58
【问题描述】:

我有一个分段控件,选中时需要蓝色未选中时需要白色。我在未选择时设置色调颜色时遇到问题,由于某种原因,它总是变成灰色。

这就是它的样子:

蓝色边框实际上是一个带有一些边框颜色的 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

没有成功。 :(

【问题讨论】:

    标签: colors background uisegmentedcontrol


    【解决方案1】:

    背景色效果很好

    self.backgroundColor = .red
    

    在 iOS 13 中运行良好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2015-11-01
      相关资源
      最近更新 更多