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: 882))
}
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()
}
}
网友评论