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

这是我的代码和屏幕截图。


创建此警报视图的代码是:

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


因此,如果有人可以告诉我如何将其带回到屏幕中央。任何帮助将不胜感激。

最佳答案

尝试通过设置UIAlertView的transform属性

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

关于ios - 警报 View 由于在其中添加了文本字段而向上移动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17170296/

10-14 20:36
查看更多