如何在UIPickerView中创建两个以上的视图?

时间:2017-02-06 14:38:04

标签: ios swift uipickerview

以下是选择器视图的功能

public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    if(pickerView == firsttype)
    {
        // create view as here it image and text view 

        let myView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 30))
        let incomecat:CategoryIncome = cateIncomeData.object(at: row) as! CategoryIncome
        let myImageView = UIImageView(frame: CGRect(x: 0, y: 5, width: 20, height: 20))
        let myLabel = UILabel(frame: CGRect(x: 40, y: 5, width:60, height: 20))
        myLabel.text = name

        let myLabelcat = UILabel(frame: CGRect(x: 20, y: 5, width:10, height: 20))
        myLabelcat.text = id 
        myImageView.image = UIImage(named:image)
        myView.addSubview(myImageView)
        myView.addSubview(myLabel)

        return myView
    }

    //second view in else condition
    else
    {
        // second view 
        let myView1 = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 30))
        let myImageView = UIImageView(frame: CGRect(x: 0, y: 5, width: 20, height: 20))
        let myLabel = UILabel(frame: CGRect(x: 40, y: 5, width:60, height: 20))
        myLabel.text = text
        myImageView.image = UIImage(named:image2)
        myView1.addSubview(myImageView)
        myView1.addSubview(myLabel)
        return myView1
    }
}

0 个答案:

没有答案