gpt4 book ai didi

iphone - 带有两个文本字段和两个按钮的 UIAlertView

转载 作者:可可西里 更新时间:2023-11-01 03:01:09 26 4
gpt4 key购买 nike

问题 - 我想要一个包含标题、两个带占位符的文本字段和两个按钮的 UIAlertView。到目前为止我所做的 - 我已经使用了这段代码,我得到了我提到的所有这些的确切 UIAlertView 但是当 View 被加载时似乎首先出现在底部然后出现进入 View 的中间。

    -(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 的属性 alertViewStyle 来获得不同类型的警报 View ,也可以使用文本字段。

可能的值:

  • UIAlertViewStyleDefault
  • UIAlertViewStyleSecureTextInput
  • UIAlertViewStylePlainTextInput
  • UIAlertViewStyleLoginAndPasswordInput

您可以使用 UIAlertViewStyleLoginAndPasswordInput 获取带有两个文本字段的 UIAlertView,然后您可以自定义文本字段的一些属性:

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

您可以在 UIAlertViewDelegate 的 alertView:clickedButtonAtIndex: 上访问文本字段的值。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"1 %@", [alertView textFieldAtIndex:0].text);
NSLog(@"2 %@", [alertView textFieldAtIndex:1].text);
}

关于iphone - 带有两个文本字段和两个按钮的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10389635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com