Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. var x: CGFloat = 1
  2. var y: CGFloat = 1
  3. var x1: CGFloat = 1
  4. var y1: CGFloat = 1
  5. var x2: CGFloat = 1
  6. var y2: CGFloat = 1
  7.  
  8. let textfield1: UITextField = UITextField()
  9.  
  10. let textfield2: UITextField = UITextField()
  11. let textfield3: UITextField = UITextField()
  12.  
  13. textfield1.frame = CGRect(x: x+20, y: y+280, width: 300, height: 30)
  14. textfield1.placeholder = "Enter What you Eat BreakFast"
  15.  
  16. textfield1.font = UIFont.systemFont(ofSize: 15)
  17. textfield1.borderStyle = UITextBorderStyle.roundedRect
  18. textfield1.autocorrectionType = UITextAutocorrectionType.yes
  19. textfield1.keyboardType = UIKeyboardType.default
  20. textfield1.returnKeyType = UIReturnKeyType.done
  21. textfield1.clearButtonMode = UITextFieldViewMode.whileEditing
  22. textfield1.contentVerticalAlignment = UIControlContentVerticalAlignment.center
  23. textfield1.contentHorizontalAlignment = UIControlContentHorizontalAlignment.fill
  24. self.view.addSubview(textfield1)
  25.  
  26.  
  27. y += 100-a
  28.  
  29.  
  30. textfield2.frame = CGRect(x: x1+20, y: y1+320, width: 100, height: 30)
  31.  
  32. textfield2.placeholder = "Number"
  33. textfield2.font = UIFont.systemFont(ofSize: 15)
  34. textfield2.borderStyle = UITextBorderStyle.roundedRect
  35. textfield2.autocorrectionType = UITextAutocorrectionType.yes
  36. textfield2.keyboardType = UIKeyboardType.default
  37. textfield2.returnKeyType = UIReturnKeyType.done
  38. textfield2.clearButtonMode = UITextFieldViewMode.whileEditing
  39. textfield2.contentHorizontalAlignment = UIControlContentHorizontalAlignment.center
  40. textfield2.contentVerticalAlignment = UIControlContentVerticalAlignment.center
  41. self.view.addSubview(textfield2)
  42.  
  43. y1 += 100-a
  44.  
  45.  
  46.  
  47. textfield3.frame = CGRect(x: x2+220, y: y2+320, width: 100, height: 30)
  48. textfield3.placeholder = "Slect Qty"
  49. textfield3.font = UIFont.systemFont(ofSize: 15)
  50. textfield3.borderStyle = UITextBorderStyle.roundedRect
  51. textfield3.autocorrectionType = UITextAutocorrectionType.yes
  52. textfield3.keyboardType = UIKeyboardType.default
  53. textfield3.returnKeyType = UIReturnKeyType.done
  54. textfield3.clearButtonMode = UITextFieldViewMode.whileEditing
  55. textfield3.contentHorizontalAlignment = UIControlContentHorizontalAlignment.center
  56. textfield3.contentVerticalAlignment = UIControlContentVerticalAlignment.center
  57. self.view.addSubview(textfield3)
  58.  
  59. y2 += 100-a
  60.  
  61. let toolbar = UIToolbar()
  62. toolbar.sizeToFit()
  63. toolbar.backgroundColor = UIColor.brown
  64. let donebutton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donepressed))
  65. let flexispace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
  66. let cancelbutton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelpressed))
  67. toolbar.setItems([cancelbutton,flexispace,donebutton], animated: false)
  68.  
  69. textfield3.inputAccessoryView = toolbar
  70. textfield3.inputView = picker
  71.  
  72.  
  73.  
  74. self.dict["Food1"] = textfield1.text!
  75.  
  76. self.dict["Quantity"] = textfield2.text!
  77.  
  78. self.dict["Choice"] = textfield3.text!
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85. func donepressed()
  86. {
  87.  
  88. if textfield3.isFirstResponder{
  89.  
  90. textfield3.resignFirstResponder()
  91. }
  92.  
  93. }
  94. func cancelpressed(){
  95.  
  96. if textfield3.isFirstResponder{
  97.  
  98. textfield3.resignFirstResponder()
  99. }
  100.  
  101.  
  102. }
  103.  
  104. func numberOfComponents(in pickerView: UIPickerView) -> Int {
  105. return 1
  106. }
  107. func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
  108. return choose.count
  109. }
  110. func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
  111. return choose[row]
  112. }
  113. func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
  114. textfield3.text = choose[row]
  115.  
  116. }
  117.  
  118.  
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement