我使用以下代码显示带有文本字段的 UIAlertView:
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Rename", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField* textField = [alertView textFieldAtIndex:0];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
[alertView show];
结果在 iOS 5.1 上如下所示:
在 iOS 6.1 上:
如您所见,清除按钮比 iOS 6.1 上的按钮要高一些。知道如何正确居中按钮吗?添加 textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
也无济于事。
(显然,这是 iOS 6.1 中的一个错误,但也许有人知道解决方法。此外,警报视图中文本字段的高度在不同的操作系统版本中似乎也不同,但这是另一个问题。)