Professional Documents
Culture Documents
You have 2 free member-only stories left this month. Sign up for Medium and get an extra one.
Member-only story
Search Medium Write Sign up Sign In
424
SwiftUI
Betterapps.Lesscode.
Contents
User Inputs: Toggle, Slider, TextField, picker, datePicker
and SegmentedControl
Toggle
The purpose of Toggle is simple: it is used to bind a property. In
some cases, we can use it to alter the screen, showing or hiding
other views.
SwiftUI — Toggle
iPhone screenshot
TextField
To use a TextField we just need to specify a placeholder(String)
and a binding.
5 Section {
6 TextField("Username", text: $username)
7 }
8 }
9 }
10 }
SwiftUI — TextField
Picker
Picker has a plus in SwiftUI. Using it inside a Form the app will
navigate to a detail view with the option list.
Segmented Control
Segmented control is a nice tool to show different views on the
same screen.
SwiftUI — SegmentedControl
Containers
ScrollView
Implement it via the ScrollView view:
SwiftUI — ScrollView
List of Items
To show a table in SwiftUI we should use a List view. The List
can show static or dynamic content based on your needs.
However, it is simple to use because we don’t need to write a lot
of code to register the cell or to tell it how many rows there are,
etc.
SwiftUI — List
Form
SwiftUI’s forms work as containers, so we can add other views
inside them and they will automatically adapt their behaviour
and styling.
Presentation
This section shows some of the methods we have to present the
information.
Alert
To create a simple alert we must define a title and message, and
add a dismiss button.
ActionSheet
The ActionSheet has the same implementation as Alert.
SwiftUI — ActionSheet
Popover
SwiftUI — Popover
SwiftUI Application
If you want to see the previous examples and other components
of SwiftUI, I have created an example project where we can see
how to create an application using SwiftUI. This is the
repository link:
https://github.com/lucasPelizza/SimpleSwiftUIExample/tree/ma
ster
SwiftUI Examples
Final words
I hope that this article was helpful for you!
171 3.9K 91
1.4K 20 472 2
See all from Lucas Pelizza See all from Better Programming
3.1K 99 3.4K 40
Help Status Writers Blog Careers Privacy Terms About Text to speech