您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页IOS UIPickerView 滑动选择器

IOS UIPickerView 滑动选择器

来源:保捱科技网


import UIKit
class Tab_my:UIViewController,UIPickerViewDelegate,UIPickerViewDataSource{

    var db:[String] = [String]();
    //
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        //
        db = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s"];
        let pickerView:UIPickerView = UIPickerView(frame: CGRect(x: 20, y: 100, width: 50, height: 450))
        pickerView.transform = CGAffineTransform(rotationAngle: -90*(.pi/180))
        pickerView.frame.origin.x = 10
        // 设置 UIPickerView 代理
        pickerView.delegate = self
        // 设置 UIPickerView 数据源
        pickerView.dataSource = self
        self.view.addSubview(pickerView)
        
      
        
        
    }
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        1
    }
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        db.count;
    }
    //方格里面 自定义视图
    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
        let lb:UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
        lb.text = db[row]
        lb.transform = CGAffineTransform(rotationAngle: 90*(.pi/180))
        return lb;
    }
    //方格里面 默认视图,只需要给数据
    /*func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return db[row];
    }*/
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        print(db[row]);
    }
    
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务