Show UIPickerView in UIViewConrtroller

Updated 23 July 2024

Save

Hello readers, today in our swift learning journey we will discuss another interesting topic of Swift “UIPickerView”.

In Swift, UIPickerView is a fundamental user interface component in iOS development that allows users to make selections from a set of options presented in a scrollable, column-based view. The UIPIckerView in Swift is commonly used when you want to provide users with the options to select from the list.

Prerequisites

Before we dive into the UIPickerView in Swift, you must have a basic understanding of iOS development using Swift and Xcode. Assuming that you are familiar with setting up user interfaces and handling basic interactions in iOS apps we will directly learn about the UIPickerView integration.

Step 1: Setting Up the UIPickerView

Firstly, we need to set up the Picker View on our UIViewController and make the connection to our ViewController class.

Step2: Extends the Delegates of UIPickerView

Next, we will extend the delegates of the Picker View and implement its functions on our ViewController.

In UIPickerView, we can create multiple scrollable picker views that work autonomously for every section. With some appropriate logic, you can access their data and use it individually for different purposes.

Step 3: Displaying the UIAlertController

Once you integrate the methods and add the logic accordingly, you can then provide the self to the picker view delegates to present the view on your UIViewController.

Example Code

Here is the example code where we have created a date picker containing the 3 components and displaying the selected date on the label.

Output:-

Here is the output of the above code.

Conclusion

In this blog, we learned about the UIPickerView its delegates, functions and use cases. We have also created an example app for date pickers through the Picker View.

You can continue your learning journey with us through our Mobikul Blogs.

Additionally you can also checkout our Flutter App Development Services here.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home