繁体   English   中英

objective-c,如何在UIAlertView上添加UITextField

[英]objective-c, How to add a UITextField on UIAlertView

我想等待通过警告对话框输入用户名,如何在UIAlertView上添加UITextField

自iOS5以来,这已经发生了变化 您现在可以使用样式创建UIAlertView。

UIAlertView现在有一个属性 - alertViewStyle ,您可以将其设置为其中一个枚举值

  • UIAlertViewStyleDefault
  • UIAlertViewStyleSecureTextInput
  • UIAlertViewStylePlainTextInput
  • UIAlertViewStyleLoginAndPasswordInput

创建警报视图后,将其设置为样式并显示它。 关闭警报后,您可以使用警报视图的textFieldAtIndex:属性访问字段的内容。

像这样 :

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Twitter  Login" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Sign In", nil];

myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
myTextField.placeholder=@"Enter User Name";
[myTextField becomeFirstResponder];
[myTextField setBackgroundColor:[UIColor whiteColor]];
myTextField.textAlignment=UITextAlignmentCenter;

// myTextField.layer.cornerRadius=5.0; Use this if you have added QuartzCore framework

[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];

这已经讨论了几次。 这是一篇很好的帖子: 带文本输入的UIAlertView

像这样:

UIAlertView * myAlertView = [[UIAlertView alloc] initWithTitle:@“Twitter Login”消息:@“\\ n \\ n \\ n”委托:self cancelButtonTitle:@“取消”otherButtonTitles:@“登录”,nil];

    myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
    myTextField.placeholder=@"Enter User Name";
    [myTextField becomeFirstResponder];
    [myTextField setBackgroundColor:[UIColor whiteColor]];
    myTextField.textAlignment=UITextAlignmentCenter;
    // myTextField.layer.cornerRadius=5.0; Use this if you have added QuartzCore framework
        [myAlertView addSubview:myTextField];
    [myAlertView show];
    [myAlertView release];

希望这能解决你的问题.......

我在我的博客中创建了一个帖子,主题是“如何从XIB向UIAlertView添加UITextField”。 使用XIB添加比纯编码更容易。 请参考以下链接。

http://creiapp.blogspot.com/2011/08/how-to-add-uitextfield-to-uialertview.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM