UIAlertController 文本字段宽度比平时小得多
UIAlertController textfield width is way smaller than usual
所以我有一个 UIAlertController
添加了一个 UITextField
作为输入,但出于某种原因,文本字段似乎比预期的要小得多。知道为什么吗?
这是截图
这是代码
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];
这是一个非常有趣的错误。我们正在处理的项目有一个名为 Pixate Freestyle 的库,它使用 CSS 来设置应用程序元素的样式。它通过设置样式打破了文本字段。我们将其从项目中删除并对其进行了本地样式化。问题解决了。希望这对您有所帮助!
所以我有一个 UIAlertController
添加了一个 UITextField
作为输入,但出于某种原因,文本字段似乎比预期的要小得多。知道为什么吗?
这是截图
这是代码
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];
这是一个非常有趣的错误。我们正在处理的项目有一个名为 Pixate Freestyle 的库,它使用 CSS 来设置应用程序元素的样式。它通过设置样式打破了文本字段。我们将其从项目中删除并对其进行了本地样式化。问题解决了。希望这对您有所帮助!