开发者

objective-c, How to add a UITextField on UIAlertView

I want to wait for a username input by alert dialog, how to add UITe开发者_运维百科xtField on UIAlertView


This has changed since iOS5. You can now create a UIAlertView with a style.

UIAlertView now has a property - alertViewStyle that you can set to one of the enum values

  • UIAlertViewStyleDefault
  • UIAlertViewStyleSecureTextInput
  • UIAlertViewStylePlainTextInput
  • UIAlertViewStyleLoginAndPasswordInput

Once you've created the alert view, you set it style and display it. After dismissing the alert, you can access the contents of the fields using the textFieldAtIndex: property of the alert view.


Like this :

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


Like this:

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

Hope this will solve your problem.......

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜