2008-11-12 63 views

回答

7

我发现了一个解决方案: http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html

这里是为我工作的代码。

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 

CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0); 
[myAlertView setTransform:myTransform]; 

[myTextField setBackgroundColor:[UIColor whiteColor]]; 
[myAlertView addSubview:myTextField]; 
[myAlertView show]; 
[myAlertView release]; 
4

您需要创建弹出窗口(UIAlertView)并将UITextField(或任何您想使用的组件)添加到它作为子视图。 UIAlertView不会为您添加的组件自动调整大小,因此您必须通过向其中添加文本来将它的那部分一起破解。该文本将增加弹出窗口的高度,并提供您不会添加太多被您的组件隐藏的内容。

1

将此函数添加到您的代码中,在显示警报之前调用它。

  • (无效)willPresentAlertView:(UIAlertView中*)alertView { alertView.frame = CGRectMake(X,Y,宽度,heigth); }
1

一种调整您的UIAlertView中提示...

由于米伦Milkovski上/下,如果你设置了UIAlertView中的委托写道:

UIAlertView* theAlert = [[UIAlertView alloc] initWithTitle:@"Lah" 
                message:@"dee dah" 
                delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:nil]; 
//NSLog(@"Pre Show: alert frame x,y: %f,%f, alert frame width,height: %f,%f", theAlert.frame.origin.x,theAlert.frame.origin.y, theAlert.frame.size.width, theAlert.frame.size.height); 
[retrievingListAlert show]; 

然后,您可以修改通过定义以下UIAlertView回调(在委托类中 - 在这种情况下,因为我们使用self,与创建UIAlertView的位置相同)的UIAlertView框架:

(void)willPresentAlertView:(UIAlertView *)alertView { 
    //NSLog(@"willPresentAlertView: alert frame midx,midy: %f,%f, alert frame width,height: %f,%f", alertView.frame.origin.x, alertView.frame.origin.y, alertView.frame.size.width, alertView.frame.size.height); 
    alertView.frame = CGRectMake(x, y, width, heigth); 
} 

我发现在其他时间设置帧不起作用。看起来show功能修改框架,大概是在自动调整内容的同时。

相关问题