美文网首页
对iOS14 系统前、后的分割线适配(UIPickerView)

对iOS14 系统前、后的分割线适配(UIPickerView)

作者: iOS程序猿猿猿猿 | 来源:发表于2023-02-23 10:58 被阅读0次

    extension UIPickerView {
    func adapterPickerView() {
    self.tag = 9999
    if #available(iOS 14.0, ) {
    self.subviews[1].backgroundColor = .clear
    let topLineImgView = UIImageView.init(frame: .zero)
    self.subviews[1].addSubview(topLineImgView)
    topLineImgView.snp.makeConstraints { (make) in
    make.top.equalToSuperview()
    make.centerX.equalToSuperview()
    make.height.equalTo(2)
    make.width.equalTo(SKScale(float: 88
    2))
    }
    topLineImgView.image = UIImage.init(named: "icon_Sheet_topImgView")

            let bottomLineImgView = UIImageView.init(frame: .zero)
            self.subviews[1].addSubview(bottomLineImgView)
            bottomLineImgView.snp.makeConstraints { (make) in
                make.bottom.equalToSuperview()
                make.centerX.equalToSuperview()
                make.height.equalTo(2)
                make.width.equalTo(SKScale(float: 88*2))
            }
            bottomLineImgView.image = UIImage.init(named: "icon_Sheet_topImgView")
        }else{
            for  view in self.subviews {
                if view.frame.size.height <= 2 {
    
                    let bgView = UIView.init(frame: .zero)
                    view.addSubview(bgView)
                    bgView.snp.makeConstraints { (make) in
                        make.top.equalToSuperview()
                        make.bottom.equalToSuperview()
                        make.left.equalToSuperview()
                        make.right.equalToSuperview()
                    }
                    bgView.backgroundColor = self.backgroundColor
    
                    let topLineImgView = UIImageView.init(frame: .zero)
                    view.addSubview(topLineImgView)
                    topLineImgView.snp.makeConstraints { (make) in
                        make.top.equalToSuperview()
                        make.bottom.equalToSuperview()
                        make.centerX.equalToSuperview()
                        make.width.equalTo(SKScale(float: 88*2))
                    }
                    topLineImgView.image = UIImage.init(named: "icon_Sheet_topImgView")
                }
            }
        }
    
    }
    

    }

    //适配代码一定要写在数据源之后
    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

        if pickerView.tag != 9999 {
            pickerView.adapterPickerView()
        }
    

    }

    相关文章

      网友评论

          本文标题:对iOS14 系统前、后的分割线适配(UIPickerView)

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