narciero
narciero

Reputation: 615

Add an inputview to UIButton for on click event iOS

I am building a page for a Swift iOS app and I want the user to be able to specify the date range for a graph. At the top of my graph I want the user to select a date range by clicking on a button which will gray out the screen and bring up a picker view on the bottom of the screen to select the date range. It's very similar to how the myfitnesspal app does it (below):

As you can see when they click on the calendar button it brings up a pickerview while graying out the rest of the screen and only recognizes touches to the pickerview. I basically want to replicate this kind of method that allows me to bring up a custom picker when a button is clicked.

I have tried using UIActionSheet however that is now deprecated and I've read that an action sheet should not be used for this kind of functionality.

Upvotes: 1

Views: 1374

Answers (1)

Shripada
Shripada

Reputation: 6524

You can do this by designing a view controller such that-

  1. It has a background view that covers entire screen with background color as black with some alpha say 0.3. This view will serve to block out any touches on the views behind it. Basically it will have that translucent background effect.

  2. Have your actual view such as picker view as a sibling of this, add other siblings like the cross button, etc. You can use the cross button to initiate closing of the view.

  3. Present this controller as a child view controller on the controller where you need this.

Upvotes: 1

Related Questions