Pradip Kumar Pradip Kumar - 2 months ago 6x
Swift Question

Add tableview in AlertController dynamically in swift , how?

I need to display the items like

. How can I do this??
or if I am getting the question wrong , suggest me geeks?

My screen should be like

Thanks in advance.

enter image description here


Create a new UIViewController, and before presenting it set modalPresentationStyle property to be UIModalPresentationOverCurrentContext. The UIViewController's view must have set clear color as background color and to be overlaid by a UIImageView with alpha 0.5 and has gray color. This will create the semi-transparent effect, then add other UI elements you need (table view, buttons, etc).

Let's say you have CustomViewController for displaying the content above you described. You'll present it using the following statments:

let customVC = CustomViewController()
customVC.modalPresentationStyle = .OverCurrentContext
presentViewController(customVC, animated: false, completion: nil)

Before that, customize CustomViewController's in the following way:

  • CustomViewController view must have background color set to clear color

  • An image view which overlays CustomViewController view, set it's alpha = 0.5, and background color to dark gray color.

  • A content view (where you'll put table view and rest of UI components you need)

As a result you'll have this view hierarcy:

enter image description here