Problem- 我想要一个 UIAlertView,其中包含一个标题、两个带占位符的文本字段和两个按钮。到目前为止我做了什么- 我已经使用了这段代码,我得到了精确的 UIAlertView 以及我提到的所有这些,但是当视图加载时,它似乎首先出现在底部,然后进入视图的中间。
-(void)showalert{
disclaimerAgreedAlertView = [[UIAlertView alloc] initWithTitle:@" "
message:@" "
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Login", nil];
userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 15.0, 245.0, 25.0)];
userNameTextField.delegate=self;
[userNameTextField setBackgroundColor:[UIColor whiteColor]];
[userNameTextField setKeyboardType:UIKeyboardTypeDefault];
userNameTextField.placeholder=@"Username";
userNameTextField.secureTextEntry=NO;
[disclaimerAgreedAlertView addSubview:userNameTextField];
passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
passwordTextField.delegate=self;
[passwordTextField setBackgroundColor:[UIColor whiteColor]];
[passwordTextField setKeyboardType:UIKeyboardTypeDefault];
passwordTextField.placeholder=@"Password";
passwordTextField.secureTextEntry=YES;
[disclaimerAgreedAlertView addSubview:passwordTextField];
disclaimerAgreedAlertView.tag=99;
[disclaimerAgreedAlertView show];
disclaimerAgreedAlertView.frame= CGRectMake(5, 400, 320, 160);
}
然后我尝试了一些未记录的 api,它们给了我想要的结果,但我担心它可能会导致我的应用程序被拒绝。
那么,有什么解决办法吗?
从 iOS 5 开始可以使用该属性警报视图样式UIAlertView 来获取不同类型的警报视图,也带有文本字段。
可能的值:
- UIAlertView 样式默认
- UIAlertViewStyleSecureTextInput
- UIAlertViewStylePlainTextInput
- UIAlertViewStyleLoginAndPasswordInput
您可以使用UIAlertViewStyleLoginAndPasswordInput获取具有两个文本字段的 UIAlertView,然后您可以自定义 textFields 的一些属性:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Your_Title" message:@"Your_message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
// Alert style customization
[[av textFieldAtIndex:1] setSecureTextEntry:NO];
[[av textFieldAtIndex:0] setPlaceholder:@"First_Placeholder"];
[[av textFieldAtIndex:1] setPlaceholder:@"Second_Placeholder"];
[av show];
您可以访问文本字段的值警报视图:clickedButtonAtIndex:UIAlertViewDelegate 的。
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"1 %@", [alertView textFieldAtIndex:0].text);
NSLog(@"2 %@", [alertView textFieldAtIndex:1].text);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)