Start a Project

Load UIPickerView From Bottom Of The Screen

In this article you will learn about How To Load UIpicketView From Bottom Of The Screen in Swift.

Introduction

UIPickerView is a user interface element in iOS that allows users to choose a value from a list of options.

It’s similar to a dropdown or a scrolling list and is often used in scenarios like selecting a date, time.

What is UIPickerView In Swift

In Swift UIPickerView is a user interface component from the UIKit framework that presents a rotating scrollable list of items from which users can select.

It functions like a wheel with rows of options, UIPickerView can display single or multiple columns.

A picker can have more than one column (component), each providing different options. For example, a date picker might have separate columns for day, month, and year.

You can check here for more information about UIPickerView

Implementation

We need to follow below mention steps to implement Load UIPickerView From Bottom Of TheScreen.

1. Create New Projects:

First of all we need to create a new project where you will integrate UIPickerView.

2. Create a UITextField

After that we need to add a UITextField either programatically or using Storyboard.

3. Create a PickerView

In this steps you need to create a PickerView.

This Swift function createPickerView() sets up a UIPickerView as the input method for a UITextField, replacing the default keyboard with the picker.

4. Create a dismissPickerView

After that we need to create a dismissPickerView.

dismissPickerView() is function creates a toolbar with a “Done” button that allows users to dismiss the UIPickerView when they are done selecting a value. 

5. Add No of Component

The function numberOfComponents specifies that the UIPickerView will have one component or column.

6. Add Number Of Rows In Component

The function pickerView(_:numberOfRowsInComponent:) returns the number of rows (or items) in the specified component (column) of the UIPickerView.

7. Add Title For Row

The function pickerView(_:titleForRow:forComponent:) provides the text for each row in the UIPickerView. In this code, it returns the item from the countryList  array corresponding to the row’s index

8. Add didSelectRow

The function pickerView(_:didSelectRow:inComponent:) is called when a row is selected in the UIPickerView.

In this code, when a user selects a row, it assigns the selected country from the countryList array to the selectedCountry variable.

Then, it updates the textfield.text to display the selected country.

Full Code:

Output

Conclusion

In this article we have discussed about Load UIPickerView From Bottom Of The Screen.

Hope this blog is helpful to understand this topic.

Thanks for reading this blog. You can also check other blogs from here for more knowledge.

Exit mobile version