swift - 代码创建 pickerView 显示或隐藏横线

 1 import UIKit
 2 
 3 class VC1: UIViewController {
 4     
 5     fileprivate lazy var pickerV : UIPickerView = {
 6         let v = UIPickerView(frame: CGRect(x: 100, y: 100, width: 200, height: 400))
 7         v.delegate = self
 8         v.dataSource = self
 9         v.backgroundColor = .orange
10 
11         return v
12     }()
13 
14     override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
15      view.addSubview(pickerV)
16         pickerV.showsSelectionIndicator = false
17         
18     }
19 }
20 
21 extension UIViewController:UIPickerViewDelegate, UIPickerViewDataSource{
22     public func numberOfComponents(in pickerView: UIPickerView) -> Int {
23         return 1
24     }
25     
26     public func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
27         return 200
28     }
29     public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
30         return 10
31     }
32     
33     public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
34         pickerView.subviews[1].backgroundColor = UIColor.blue
35         pickerView.subviews[1].isHidden = false
36         pickerView.subviews[2].backgroundColor = UIColor.purple
37         pickerView.subviews[2].isHidden = false
38         
39         
40         /// 俩根线中间的VIEW
41         let v = UIView()
42         v.frame = CGRect(x: 0, y: 0, width: 50, height:100)
43         v.backgroundColor = UIColor.green
44         return v
45     }
46 }



 

转载于:https://www.cnblogs.com/qingzZ/p/9340916.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值