美文网首页iOS
swift5 iOS13 UISegmentedControl

swift5 iOS13 UISegmentedControl

作者: 克伟看世界 | 来源:发表于2020-04-26 17:49 被阅读0次

    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

        }()

    相关文章

      网友评论

        本文标题:swift5 iOS13 UISegmentedControl

        本文链接:https://www.haomeiwen.com/subject/ghyjwhtx.html