更新xcode11后iOS13适配 UISegmentedControl问题

之前项目中使用UISegmentedControl样式,修改了选中的样式,如图一


图一

在iOS13中 ,UISegmentedControl默认样式变为白底黑字,如图二

图二

解决方法:

extension UISegmentedControl {

    public func ensureiOS12Style() {

        if#available(iOS13, *) {

            lettintColorImage =UIColor.white.asImage(CGSize.init(width:self.wk_size.width, height:self.wk_size.height))

            letDividerColorImage =UIColor.white.asImage(CGSize.init(width:1, height:self.wk_size.height))

            setBackgroundImage(UIColor.white.asImage(CGSize.init(width:self.wk_size.width, height:self.wk_size.height)), for: .normal, barMetrics: .default)

            setBackgroundImage(tintColorImage, for: .selected, barMetrics: .default)

            setBackgroundImage(tintColorImage, for: .highlighted, barMetrics: .default)

            setBackgroundImage(tintColorImage, for: [.highlighted, .selected], barMetrics: .default)

            setDividerImage(DividerColorImage, forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default)

            setDividerImage(DividerColorImage, forLeftSegmentState: .selected, rightSegmentState: .selected, barMetrics: .default)

            self.apportionsSegmentWidthsByContent = true

            layer.borderColor = UIColor.white.cgColor

            layer.borderWidth=0

        }

    }

}

extension UIColor {

    publicfuncasImage(_size:CGSize) ->UIImage? {

        varresultImage:UIImage? =nil

        letrect =CGRect(x:0, y:0, width: size.width, height: size.height)

        UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.main.scale)

        guard let context = UIGraphicsGetCurrentContext() else {

            returnresultImage

        }

        context.setFillColor(self.cgColor)

        context.fill(rect)

        resultImage =UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()

        returnresultImage

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 生活不只是眼前的苟且,还有远方的苟且啊。 健康 被土豆带进了一个运动群,三天的运动打卡把自己整残了,撑墙撑得上肢蹄...
    漫漫似锦阅读 1,436评论 0 1
  • 第256天,虚泛词式的破解方法很多,讲议上大概有四类的破解,你记得多少? 第257天,今天我们要修炼“以偏概全式”...
    心境_01阅读 2,498评论 0 0
  • 阳台外,正对面,草厦子,麻将屋,空空也,中年男,自上午,至中午,持续放,我年轻,流行的,经典歌,又沉浸,又感怀,瞬...
    smile丝唛小主阅读 832评论 0 3