OGeek|极客世界-中国程序员成长平台

标题: ios - 警报 View 中的两个文本字段,它们之间有空格 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:18
标题: ios - 警报 View 中的两个文本字段,它们之间有空格

我有一个带有文本字段的 UIAlertView。有人可以帮助我如何在它们之间留出一些空间吗?

newBoatAlert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

UITextField * alertTextField1 = [newBoatAlert textFieldAtIndex:0];
alertTextField1.keyboardType = UIKeyboardTypeDefault;
alertTextField1.placeholder = @"Name";

UITextField * alertTextField2 = [newBoatAlert textFieldAtIndex:1];
alertTextField2.frame=CGRectMake(alertTextField1.frame.origin.x, alertTextField1.frame.origin.y+alertTextField1.frame.size.height+10, alertTextField1.frame.size.width, alertTextField1.frame.size.height+40);

alertTextField2.keyboardType = UIKeyboardTypeDefault;
alertTextField2.placeholder = @"Description";
alertTextField2.secureTextEntry=NO;

现在看起来像这样:

enter image description here



Best Answer-推荐答案


您无法编辑 Apple 提供的内置 UIAlertView 样式(至少在没有可能会在下一个 iOS 版本中被破坏的肮脏技巧时不能编辑)。

如果您想自定义警报的外观,例如在文本字段之间添加空格,您应该创建自己的 UIView 子类并从头开始实现自己的警报 UI。

此外,如果您确实选择使用 Apple 的内置警报而不是滚动自己的警报,UIAlertView 现在已被弃用,您应该使用 UIAlertController反而。它为文本框提供了相同的功能,并为按钮提供了更多自定义选项(尽管您仍然无法更改布局)。

关于ios - 警报 View 中的两个文本字段,它们之间有空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30260454/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4