UIAlertController textfield width is way smaller than usual

坚强是说给别人听的谎言 提交于 2019-12-06 01:14:35

问题


So I have a UIAlertController with a UITextField added for an input but for some reason the textfield appears to be much smaller than it's supposed to be. Any idea why?

Here is the Screenshot

Here is the Code

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];

Thanks!


回答1:


This was a very interesting bug. The project we were working on had a library called Pixate Freestyle, which uses CSS to style app's elements. It was breaking the textfields by styling it. We removed it from the project and styled it natively. The problem was solved. Hope this helps!




回答2:


Presenting through the root controller solved my problem:

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];



来源:https://stackoverflow.com/questions/32721782/uialertcontroller-textfield-width-is-way-smaller-than-usual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!