UIAlertController文本字段宽度比平常小
所以我有一个UIAlertController
与一个UITextField
为input添加,但由于某种原因,文本字段似乎比它应该小得多。 任何想法为什么?
这是截图
这是守则
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"This is title" message:@"This is message" preferredStyle:UIAlertControllerStyleAlert]; [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.keyboardType = UIKeyboardTypeNumberPad; textField.placeholder = @"I am a placeholder"; }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Submit" style:UIAlertActionStyleDefault handler:nil]; [alert addAction:okAction]; [self presentViewController:alert animated:YES completion:nil];
谢谢!
通过根控制器呈现解决了我的问题:
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];