Member-only story

Adding Text Fileld in UIAlertController like a promt box in iOS

Mr.Javed Multani
1 min readOct 5, 2020

--

Swift

let alert = UIAlertController(title: "Hello",
message: "Welcome to the world of iOS",preferredStyle: UIAlertControllerStyle.alert)
let defaultAction = UIAlertAction(title: “OK”, style: UIAlertActionStyle.default) { (action) in}defaultAction.isEnabled = false
alert.addAction(defaultAction)alert.addTextFieldWithConfigurationHandler { (textField) in
textField.delegate = self}
present(alert, animated: true, completion: nil)

Objective-C

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Hello"
message:@"Welcome to the world of iOS”preferredStyle:UIAlertControllerStyleAlert];UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefaulthandler:^(UIAlertAction * action) {}];defaultAction.enabled = NO;
[alert addAction:defaultAction];[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.delegate = self;}];
[self presentViewController:alert animated:YES completion:nil];

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet