Progress bars are great for showing progress of downloading files and other tasks that take time. This video shows how to create progress bars in iOS and how to use them in your apps.
- [Instructor] If you're ever doing something in your application like downloading a file that is not extremely small, you might want to show the progress to your user. You can do that with the built in element, a progress bar. You can create a progress bar through the library. Open it up, search for a Progress View. Click and drag one out to the screen. I'll put it there. Extend it and then shift, option, command, and equals to add some auto layout constraints.
So we have our progress view right here. And the slider right here. We'll have the slider update the progress view as well as the label. I'm going to option click ViewController.swift and then right click and drag from the progress view into the code right underneath label. Just like that. And here it's saying that the type is UI View. That means I clicked and dragged from the wrong element. It's a little bit difficult to click and drag from that progress view, so I click Cancel to cancel out of that. I'll select the progress view in the document outline and then right click and drag from the progress view in the document outline into my code.
That makes it a little bit easier to make sure that you're dragging from the correct element. So for Connection I have Outlet. Type should be UIProgressView. And I'll name this progressView and hit return. And when I try to drag over, there's this error message saying it doesn't recognize the label class. Just cancel out if you get that message and try again, and it should work. Let's head over to the standard editor and then to ViewController.swift, and inside of sliderValueChange I'm going to call progressView.setProgress, and the progress is going to be a value between zero and one.
So we'll just use sender.value and then animated, we can just put true. Run the application, see what we get. So we have our progress bar at the bottom. I can click and drag the slider and the progress bar moves along with it. So if you ever want to use a progress bar in your application, you can simply create a progressView in your storyboard and you reference it inside of your code so you connect it as an outlet and you can set its progress value using a value between zero and one.
- Alert controllers and actions
- Sliders, progress bars, and switches
- Creating UI elements with code
- Displaying web content with Safari view controllers and WKWebView
- Creating collection view controllers
- Creating tabbed apps
- Publishing your app with App Store Connect