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 }
分类:
swift
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现