【发布时间】:2021-11-29 16:09:39
【问题描述】:
我正在为我的分段控件设置颜色,如下所示:
segmentedControl.backgroundColor = .gray
segmentedControl.selectedSegmentTintColor = .red
let textAttrs: [NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.white
]
segmentedControl.setTitleTextAttributes(textAttrs, for: .normal)
效果很好,但是当用户长按它(在设置中启用大字体)时,我得到以下信息:
如您所见,文本不可读。有没有办法为无障碍视图设置背景/色调颜色?
我找到的最佳解决方案是为标题属性中的文本设置背景颜色,如下所示:
let textAttrs: [NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.white,
.backgroundColor: segmentedControl.backgroundColor!
]
segmentedControl.setTitleTextAttributes(textAttrs, for: .normal)
let textAttrsSelected: [NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.white,
.backgroundColor: segmentedControl.selectedSegmentTintColor!
]
segmentedControl.setTitleTextAttributes(textAttrsSelected, for: .selected)
结果更好(至少文字可读),但还是不好看:
理想情况下,我希望辅助功能模式视图具有与主视图中相同的背景颜色和色调颜色。
【问题讨论】:
标签: ios uikit accessibility uisegmentedcontrol