Stokolos Ilya
Stokolos Ilya

Reputation: 378

How can I get following pop up text field in Swift?

I would like to a let user create a folder in my app. More specifically, when the user presses "add folder" button, I would like to have the following text field to pop up

enter image description here

How can I implement it?

Upvotes: 2

Views: 5762

Answers (2)

Abdul Karim Khan
Abdul Karim Khan

Reputation: 4935

For custom PopUp:

By Storyboard

Step 1: Create a UIViewController with this pop up message.

Step 2: Intead of push, Present it from your parent View and set Parent View transition style to cross dissolve.

enter image description here

By Code:

if let nav = self.navigationController
{
    UIView.transition(with:nav.view, duration:0.25, options:.transitionCrossDissolve, animations: {
        _ = nav.popViewController(animated:false)
    }, completion:nil)
}

Upvotes: 2

Sylvan M.
Sylvan M.

Reputation: 190

It's going to look something like this:

// create the actual alert controller view that will be the pop-up
let alertController = UIAlertController(title: "New Folder", message: "name this folder", preferredStyle: .alert)

alertController.addTextField { (textField) in
    // configure the properties of the text field
    textField.placeholder = "Name"
}


// add the buttons/actions to the view controller
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let saveAction = UIAlertAction(title: "Save", style: .default) { _ in

    // this code runs when the user hits the "save" button

    let inputName = alertController.textFields![0].text

    print(inputName)

}

alertController.addAction(cancelAction)
alertController.addAction(saveAction)

present(alertController, animated: true, completion: nil)

Let me know if this helps.

Upvotes: 8

Related Questions