【发布时间】:2020-06-29 16:27:34
【问题描述】:
我希望所有以前的 iOS 版本都具有 iOS 13 UISegmentedControl 外观。我尝试使用颜色和边框自定义 segmentControl。这是我的代码:
private func create(_ items: [String]) {
segmentControl.backgroundColor = .lightGray
segmentControl.cornerRadius = 10
segmentControl.borderColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.04).cgColor
segmentControl.borderWidth = 0.5
items.enumerated().forEach { (index, item) in
segmentControl.setTitle(item, forSegmentAt: index)
if let titleAttributes = titleAttributes {
segmentControl.setTitleTextAttributes([.foregroundColor: titleAttributes.color, .font: titleAttributes.font], for: .normal)
}
}
if #available(iOS 13.0, *) {
segmentControl.selectedSegmentTintColor = .white
} else {
segmentControl.tintColor = .white
}
}
上面的代码在iOS13上完美运行,但是对于之前的版本,选择的段tintColor就不合适了。我为选定的片段设置了“白色”,为背景设置了“灰色”。所选的淡色似乎使标题变淡。边框也没有显示。
附件是屏幕截图,所选段色调“白色”不正确。好像标题已经落后了。
我尝试了很多解决方案,但都不起作用。或者有什么方法可以让 iOS 13 出现在早期版本中?请帮忙。
谢谢!!!
【问题讨论】:
标签: ios swift uisegmentedcontrol swift5