Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Weitere Verwandte Inhalte

Ähnliche Bücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Ähnliche Hörbücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Controls in action

  1. 1. • Unit 2—Lesson 9: • Controls in Action
  2. 2. Controls • Buttons • Switches • Sliders • Text fields
  3. 3. Buttons (UIButton) @IBAction func buttonTapped(_ sender: Any) // Code to respond to button }
  4. 4. Buttons (UIButton)
  5. 5. Switches (UISwitch) @IBAction func switchToggled(_ sender: UISwitch) { if sender.isOn { print("The switch is on!") } else { print("The switch is off.") } }
  6. 6. Sliders (UISlider) @IBAction func sliderValueChanged(_ sender: UISlider) { print(sender.value) }
  7. 7. Configuration Sliders (UISlider) Property Description Minimum Value Lowest number value the slider may represent Maximum Value Highest number value the slider may represent Current Starting number value the slider will represent Min Image Optional image on the minimum end of the slider Max Image Optional image on the maximum end of the slider
  8. 8. Text fields (UITextField) @IBAction func keyboardReturnKeyTapped(_ sender: UITextField) { if let text = sender.text { print(text) } }
  9. 9. Text fields (UITextField) Property Description Placeholder Text Text displayed when the text field is empty Text Text displayed by the text field Capitalization How the keyboard deals with capitalization Correction Enables or disables autocorrect Keyboard Which keyboard is displayed—for example, email, web, or default Return Key Text on the return key Secure Specific text fields that don't display their contents, commonly used for passwords
  10. 10. Actions and outlets • @IBOutlet weak var toggle: UISwitch! • @IBOutlet weak var slider: UISlider! • @IBAction func buttonTapped(_ sender: UIButton) { • if toggle.isOn { • . . . • } • print(slider.value) • }
  11. 11. Controls in Action Unit 2—Lesson 9 Use Interface Builder to add buttons, switches, and sliders to a scene Create actions and outlets, write some basic code, and gain an understanding of how these tools work together
  12. 12. Lab: Basic Interactions Unit 2—Lesson 9 Create and compile an app with two buttons that, when tapped, change the contents of a label
  13. 13. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

×