我正在通过单击按钮创建警报 View 。我在其中放置了一个 UITextfield。但警报 View 在屏幕中向上移动。我无法将其带回屏幕中央。
这是我的代码和屏幕截图。
创建此警报 View 的代码是这样的:-
- (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/