Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BasicPickerVC: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
- let picker = UIPickerView()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.view.addSubview(self.picker)
- // set frame near top-left
- picker.frame = .init(x: 60.0, y: 80.0, width: 240.0, height: 160.0)
- // we don't want any resizing o ndevice rotation
- picker.autoresizingMask = []
- // so we can see its frame
- picker.backgroundColor = .yellow
- self.picker.delegate = self
- self.picker.dataSource = self
- }
- override func viewSafeAreaInsetsDidChange() {
- super.viewSafeAreaInsetsDidChange()
- //This gets called everytime the device rotates, causing the picker view to redraw and reload all components. Trying to avoid this method being called.
- print ("viewSafeAreaInsetsDidChange")
- print (self.view.safeAreaInsets)
- }
- func numberOfComponents(in pickerView: UIPickerView) -> Int {
- print("num components: 1")
- return 1
- }
- func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
- print("num rows: 30")
- return 30
- }
- func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
- print("Title for Row:", row)
- return "Row: \(row)"
- }
- }
Advertisement
Advertisement