当用户将联系人添加到他的地址簿时,我需要输入名字,中间名和姓氏。
P.S .: 最后我找到了控件,它允许:https://github.com/eaigner/CODialog
答案 0 :(得分:1)
你能建议我可以使用的东西吗?
我会通过presentViewController:animated:completion:
(ios 5+)或presentModalViewController:animated:
ios <5 (deprecated)
如果您想坚持使用提醒视图,可以在cocoacontrols.com找到替换内容。
子类注释
UIAlertView类旨在按原样使用,不支持子类化。此视图层次结构 class是私有的,不得修改。
添加文本视图正在修改视图层次结构,并可能导致拒绝appstore提交。
使用this category,您可以轻松检查任何视图的视图层次结构。 (或在调试器控制台上使用po [alertView recursiveDescription]
)
注意:这是不应在现实世界的应用程序中使用的代码。
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title"
message:@"msg"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles: nil];
UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[textFiled setText:@"dont try that at home"];
[alertView addSubview:textFiled];
[alertView show];
[alertView printSubviewsWithIndentation:4];
我们将记录此层次结构
[0]: class: 'UIImageView'
[1]: class: 'UILabel'
[2]: class: 'UILabel'
[3]: class: 'UIAlertButton'
[0]: class: 'UIImageView'
[1]: class: 'UIButtonLabel'
[4]: class: 'UITextField'
导致此
textView只是放在所有其他文件上。实际上它必须放在[2]: class: 'UILabel'
下。我们可以通过摆弄视图层次结构(循环遍历并重新排列)或通过子类化UIAlertView并覆盖layoutSubviews
来实现这一点。这两件事,苹果都不想要。
总而言之,如果涉及UIAlertView,您有3个选择:
但是,如果有人仍然相信视图层次结构 IS 是一个好主意并且比我和苹果公司的工程师更了解,那么这就是代码
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title"
message:@"Please read carefully the next 3 lines"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles: nil];
[alertView show];
CGFloat height = 25.0;
UILabel *msgLabel = [[alertView subviews] objectAtIndex:2];
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(msgLabel.frame.origin.x, msgLabel.frame.origin.y+msgLabel.frame.size.height, msgLabel.frame.size.width, height)];
[textField1 setText:@"dont try that at home"];
[textField1 setBackgroundColor:[UIColor whiteColor]];
UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectOffset(textField1.frame, 0, height + 4)];
[textField2 setText:@"REALLY! dont try that at home"];
[textField2 setBackgroundColor:[UIColor whiteColor]];
UITextField *textField3 = [[UITextField alloc] initWithFrame:CGRectOffset(textField2.frame, 0, height + 4)];
[textField3 setText:@"REALLY! dont try that at home"];
[textField3 setBackgroundColor:[UIColor whiteColor]];
NSArray *followringSubviews = [[alertView subviews] subarrayWithRange:NSMakeRange(3, [[alertView subviews] count] - 3)];
[followringSubviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
view.frame = CGRectOffset(view.frame, 0, 3*height);
}];
[alertView addSubview:textField1];
[alertView addSubview:textField2];
[alertView addSubview:textField3];
alertView.frame = CGRectUnion(alertView.frame, CGRectOffset(alertView.frame, 0, 80));
结果:
答案 1 :(得分:0)
你希望你能做到这一点。
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"msg" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
txtField.text=@"anoop here";
[alertView addSubview:txtField];
[alertView show];
编辑:
即使是自定义视图也可以完成您的工作。 (正如你在我之前的编辑中看到的那样。)
创建具有自定义形状大小,颜色,文本大小等的自定义视图,然后将其显示为模型窗口。
编辑2:
以上代码不适用于iOS7。
答案 2 :(得分:0)
将accessoryView属性用于警报视图
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"change Password " message:@"" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 300);
UIView *view = [[UIView alloc] initWithFrame:frame];
UITextField* text1 = [[UITextField alloc] initWithFrame: CGRectMake(10, 10,self.view.frame.size.width-125, 30)];
text1.backgroundColor=[UIColor whiteColor];
UITextField* text2 = [[UITextField alloc] initWithFrame: CGRectMake(10, 45, self.view.frame.size.width-125, 30)];
text2.backgroundColor=[UIColor whiteColor];
UITextField* text3 = [[UITextField alloc] initWithFrame: CGRectMake(10, 80, self.view.frame.size.width-125, 30)];
text3.backgroundColor=[UIColor whiteColor];
text1.layer.borderColor=[UIColor lightGrayColor].CGColor;
text1.layer.borderWidth=1;
text2.layer.borderColor=[UIColor lightGrayColor].CGColor;
text2.layer.borderWidth=1;
text3.layer.borderColor=[UIColor lightGrayColor].CGColor;
text3.layer.borderWidth=1;
text1.placeholder=@" Enter old password ";
[view addSubview:text1];
[view addSubview:text2];
[view addSubview:text3];
[alertView setValue:view forKey:@"accessoryView"];
view.backgroundColor = [UIColor whiteColor];
[alertView show];