Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a drop down list using swift? [closed]

What is the library to make drop down menu in swift? I am new to Xcode and the Swift language, so can anyone please direct me on how to implement the drop down list in swift?

like image 274
mazinAlmas Avatar asked May 19 '15 07:05

mazinAlmas


People also ask

How do I make a drop down list button?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.

What is drop down list example?

A drop-down list (abbreviated drop-down, or DDL; also known as a drop-down menu, drop menu, pull-down list, picklist) is a graphical control element, similar to a list box, that allows the user to choose one value from a list. When a drop-down list is inactive, it displays a single value.


2 Answers

(Swift 3) Add text box and uipickerview to the storyboard then add delegate and data source to uipickerview and add delegate to textbox. Follow video for assistance https://youtu.be/SfjZwgxlwcc

import UIKit  class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate {      @IBOutlet weak var textBox: UITextField!     @IBOutlet weak var dropDown: UIPickerView!      var list = ["1", "2", "3"]      public func numberOfComponents(in pickerView: UIPickerView) -> Int{         return 1     }      public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{          return list.count     }      func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {          self.view.endEditing(true)         return list[row]     }      func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {          self.textBox.text = self.list[row]         self.dropDown.isHidden = true     }      func textFieldDidBeginEditing(_ textField: UITextField) {          if textField == self.textBox {             self.dropDown.isHidden = false             //if you don't want the users to se the keyboard type:              textField.endEditing(true)         }     } } 
like image 51
Charles Xavier Avatar answered Sep 21 '22 03:09

Charles Xavier


A 'drop down menu' is a web control / term. In iOS we don't have these. You might be better looking at UIPopoverController. Check out this tutorial for a bit of an insight to PopoverControllers

http://www.raywenderlich.com/29472/ipad-for-iphone-developers-101-in-ios-6-uipopovercontroller-tutorial

like image 43
Chackle Avatar answered Sep 19 '22 03:09

Chackle