SwiftUI Stepper Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey it's Chris and in this tutorial I'll show  you how to add a stepper to your Swift UI   project now a stepper control allows the  user to easily increment and decrement a   value just like you see on the screen now all  right so let's dive in and see how it's used   before we begin one quick note we have a free  xco project containing sample code for all of   the Swift UI components use it for your own  projects or just to learn from get it at CWC   swiftui dkit all right so here I have an empty  xcode project so let's start by declaring our   stepper and there are a lot of different uh  different initializers you can use so let's   use one of the most basic ones where you  have a piece of text let's say Quantity and   you bind it to a value that you can increment  and decrement so here let's declare that state property and so I'll just default this  to an integer zero and here we're going   to create a binding to quantity and just  like that we have a stepper control with   the label that we specified which you  can increment and decrement the thing   is we can't see the value right so in  order to read the value you can just   read the property here and we can embed it  into this label by substituting it in like that so now we can see the value right there  but notice I can go into the negative territory   and that doesn't really make sense in this  context so if you wanted to restrict it to   a certain range you could do that as well all  we need to do is add another parameter to our   stepper initialization called in and I'm going to  restrict it from 0 to 10 and this will make it so   that when I reach zero I can't go any lower  and when I reach 10 I can't go any higher now   another thing I want to show you how to do is  to increment or decrement by a certain amount   so this is called the step value so let's say I  wanted the step value to be two well we can add   another parameter at the end called step and  let's put it to two now whenever I increment   or decrement it's always by two so that's how  easy it is to use the stepper in your project   if you want to download the sample code for  this we've got it all in a single handy xcode   project in fact it contains a sample code for  all of the Swift UI components so that you can   learn from it or copy and paste the code  into your own project just visit cc. Swift   ui- kit it's a free download I'll leave  it in the description below the video too
Info
Channel: CodeWithChris
Views: 1,234
Rating: undefined out of 5
Keywords: How to Make an App, How to Create an App, How Build a Mobile App, Xcode, Swift, iOS, Coding, Programming, iOS Development
Id: PPqyxuAg70U
Channel Id: undefined
Length: 2min 44sec (164 seconds)
Published: Tue Jun 11 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.