带有两个TextFields和两个按钮的UIAlertView [英] UIAlertView with Two TextFields and Two Buttons

查看:101
本文介绍了带有两个TextFields和两个按钮的UIAlertView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Problem - I want a UIAlertView which contains a Title, two textfields with placeholders and two buttons. What I have done till now - I have used this code, I am getting the exact UIAlertView with all these I have mentioned but when the view is getting loaded is seems to appear in the bottom first and then comes into the middle of the 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的它给了我想要的结果,但我担心它可能会导致我的应用被拒绝。

那么,对此有什么解决方案吗?

So, any solutions to this?

推荐答案

y == 400是关于手机屏幕的底部。我想,UIAlertView从未预料到会添加子视图或它的框架设置,重置它的框架要居中。你可以评论最后一行并看看会发生什么吗?

y==400 is about the bottom of a phone screen. I imagine then, the UIAlertView that never expected to either have subviews added or it's frame set, reset's it's frame to be centered. Can you comment out that very last line and see what happens?

这篇关于带有两个TextFields和两个按钮的UIAlertView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆