警报视图由于在其中添加了文本字段而向上移动

时间:2013-06-18 13:34:04

标签: ios

我正在创建一个单击按钮的警报视图。我在其中放置了一个UITextfield。但是Alertview在屏幕上向上移动。我无法将其带回屏幕中央。

这是我的代码和截图 enter image description here

,创建此警报视图的代码如下: -

- (IBAction)btn_cancelAppointment_click:(id)sender
{
    // Here We are Creating Alertview which asks for
    UIAlertView* cancelAlert = [[UIAlertView alloc] init];

    [cancelAlert setDelegate:self];
    [cancelAlert setTitle:@"Are you sure you want to request cancellation of this appointment?"];
    [cancelAlert setMessage:@"                             "];
    [cancelAlert addButtonWithTitle:@"NO"];
    [cancelAlert addButtonWithTitle:@"YES"];

    UITextField * txt_cancelNote = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 88.0, 245.0, 30.0)];

    [txt_cancelNote setBackgroundColor:[UIColor whiteColor]];
    [txt_cancelNote setBorderStyle:UITextBorderStyleRoundedRect];
    [txt_cancelNote setPlaceholder:@"Enter cancellation note"];
    txt_cancelNote.tag = 11;

    [cancelAlert addSubview:txt_cancelNote];
    cancelAlert.delegate = self;
    [cancelAlert show];
}

所以,如果有人能告诉我如何把它带回屏幕的中心。任何帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

尝试设置UIAlertView

转换属性
  UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Test" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  alertView.transform = CGAffineTransformMakeTranslation(x, y);