更新xcode11后iOS13適配 UISegmentedControl問(wèn)題

之前項(xiàng)目中使用UISegmentedControl樣式,修改了選中的樣式,如圖一


圖一

在iOS13中 ,UISegmentedControl默認(rèn)樣式變?yōu)榘椎缀谧?,如圖二

圖二

解決方法:

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

? ? }

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 生活不只是眼前的茍且,還有遠(yuǎn)方的茍且啊。 健康 被土豆帶進(jìn)了一個(gè)運(yùn)動(dòng)群,三天的運(yùn)動(dòng)打卡把自己整殘了,撐墻撐得上肢蹄...
    漫漫似錦閱讀 245評(píng)論 0 1
  • 第256天,虛泛詞式的破解方法很多,講議上大概有四類的破解,你記得多少? 第257天,今天我們要修煉“以偏概全式”...
    心境_01閱讀 341評(píng)論 0 0
  • 陽(yáng)臺(tái)外,正對(duì)面,草廈子,麻將屋,空空也,中年男,自上午,至中午,持續(xù)放,我年輕,流行的,經(jīng)典歌,又沉浸,又感懷,瞬...
    smile絲嘜小主閱讀 135評(píng)論 0 3

友情鏈接更多精彩內(nèi)容