自定义AlertView文本字段未在横向模式下正确显示

时间:2013-06-27 06:27:48

标签: iphone ios objective-c

This will work fine for me

when go to landscape mode why this is stretch

我如何解决这个问题。我正在以编程方式添加此文本字段。 见下面的代码

AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];



    delegate.alert=[[UIAlertView alloc]initWithTitle:@"Password" message:@"\n\n\n\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];


    delegate.lbl=[[UILabel alloc]init];
    delegate.lbl.frame=CGRectMake(60, 42, 200, 18);

    delegate.lbl.backgroundColor=[UIColor clearColor];
    [delegate.alert addSubview:delegate.lbl];

    delegate.lbl.text=@"Please enter the pwd";
    delegate.lbl.textColor=[UIColor grayColor];


    CGRect rect = {70, 70, 140, 30};
    delegate.txtfield1 = [[UITextField alloc] initWithFrame:rect];
    delegate.txtfield1.backgroundColor = [UIColor whiteColor];
    delegate.txtfield1.placeholder=@" Password";

    delegate.txtfield1.borderStyle = UITextBorderStyleRoundedRect;


    delegate.txtfield1.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

    delegate.txtfield1.delegate=self;
    delegate.txtfield1.secureTextEntry=YES;

    [delegate.alert addSubview:delegate.txtfield1];

    /*delegate.txtfield1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;*/

    CGRect rect1 = {70, 110, 140, 30};
    delegate.txtfield2=[[UITextField alloc]initWithFrame:rect1];
    delegate.txtfield2.backgroundColor = [UIColor whiteColor];

    delegate.txtfield2.placeholder=@" Confirm pwd";
    delegate.txtfield2.delegate=self;
    delegate.txtfield2.secureTextEntry=YES;


    delegate.txtfield2.borderStyle=UITextBorderStyleRoundedRect;

    delegate.txtfield2.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

    [[delegate.txtfield2 layer]setBorderColor:[[UIColor blackColor]CGColor]];
    [[delegate.txtfield2 layer]setBorderWidth:1.5];
    [[delegate.txtfield2 layer]setCornerRadius:3];

    [delegate.alert addSubview:delegate.txtfield2];


    delegate.SaveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    delegate.SaveButton.frame = CGRectMake(12, 150, 110, 40);
    [delegate.SaveButton setTitle:@"Save" forState:UIControlStateNormal];


    [delegate.SaveButton addTarget:self action:@selector(Save) forControlEvents:UIControlEventTouchUpInside];

    [delegate.alert addSubview:delegate.SaveButton];


    delegate.CancelButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    delegate.CancelButton.frame=CGRectMake(160, 150, 110, 40);

    [delegate.CancelButton setTitle:@"Cancel" forState:UIControlStateNormal];


    [delegate.CancelButton addTarget:self action:@selector(Cancel) forControlEvents:UIControlEventTouchUpInside];

    [delegate.alert addSubview:delegate.CancelButton];

    [delegate.alert show];

1 个答案:

答案 0 :(得分:0)

只需将代码“\ n \ n \ n \ n \ n”UITextView中取出即可将其删除。
编辑

您必须为此制作自己的自定义提醒。