पिकर व्यू एक या अधिक व्हील्स प्रदर्शित करता है जिन्हें यूजर आइटम्स चुनने के लिए मैनिपुलेट करता है। प्रत्येक व्हील - जिसे कंपोनेंट के रूप में जाना जाता है - इंडेक्स्ड पंक्तियों की एक श्रृंखला होती है जो चयन योग्य आइटम्स का प्रतिनिधित्व करती हैं।
UIPicker महत्वपूर्ण कंपोनेंट्स में से एक है और लगभग अधिकांश एप्लिकेशन में उपयोग किया जाता है। आप उन्हें ज्यादातर फॉर्म-बेस्ड एप्लिकेशन में देखेंगे।
इसके बारे में यहाँ और पढ़ें: https://developer.apple.com/documentation/uikit/uipickerview
इस पोस्ट में, हम देखेंगे कि UIPicker को ऐरे से प्रोग्रामेटिकली कैसे बनाएं और ऐरे मानों को इसमें लोड करें।
शुरुआत करते हैं
चरण 1: प्रोजेक्ट बनाएं
Xcode खोलें और सिंगल व्यू एप्लिकेशन बनाएं और नाम दें "PickerSample"
चरण 2: ViewController.swift सेटअप
ViewController.swift खोलें, चूंकि हम प्रोग्रामेटिकली बना रहे हैं इसलिए हम स्टोरीबोर्ड को बिल्कुल नहीं छूएंगे।
चरण 3: UIPickerView ऑब्जेक्ट बनाएं
let UIPicker: UIPickerView = UIPickerView()
चरण 4: डेलीगेट सेट करें और व्यू को सेंटर में लोड करें
UIPicker.delegate = self as UIPickerViewDelegate
UIPicker.dataSource = self as UIPickerViewDataSource
self.view.addSubview(UIPicker)
UIPicker.center = self.view.center
चरण 5: ViewController को डेलीगेट्स के साथ कंफर्म करें
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource
चरण 6: डेटा ऐरे बनाएं
let dataArray = ["English", "Maths", "History", "German", "Science"]
चरण 7: डेलीगेट मेथड्स इम्प्लीमेंट करें
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return dataArray.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let row = dataArray[row]
return row
}
चरण 8: एप्लिकेशन चलाएं

पूरा कोड
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
let dataArray = ["English", "Maths", "History", "German", "Science"]
override func viewDidLoad() {
super.viewDidLoad()
let UIPicker: UIPickerView = UIPickerView()
UIPicker.delegate = self as UIPickerViewDelegate
UIPicker.dataSource = self as UIPickerViewDataSource
self.view.addSubview(UIPicker)
UIPicker.center = self.view.center
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return dataArray.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let row = dataArray[row]
return row
}
}