iOS13 UISegmentedControl 设置字体后未选中颜色设置无效 代码和样式如下图
图1 效果图如果在后面更改了字体样式,则前面未选中颜色设置就无效,正确的姿势应该是(代码在最后):
正确代码 效果图附件:正确代码
lazy var segmentView:UISegmentedControl = {
letseg =UISegmentedControl(items:self.selectTitles)
seg.tintColor=kwThemeColor_B
seg.setTitleTextAttributes([NSAttributedString.Key.font :kwFontOfSystem(14)], for: .normal)
if#available(iOS13, *){
seg.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .selected)
seg.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: kwThemeColor_B], for: .normal)
seg.selectedSegmentTintColor = kwThemeColor_B
}
seg.addTarget(self, action:#selector(clickSegment(_:)), for: .valueChanged)
returnseg
}()
网友评论