2011-11-09 38 views
1

可能重复:
UIAlertView not showing message textUIAlertView中在横向模式下不显示消息

我试图创建在横向模式下的应用程序的简单UIAlertView中,但我看到的是标题和按钮,但没有实际的消息。

它与屏幕上UIAlertView的可用空间有关,就好像我删除了几个按钮,然后消息显示正常。

有没有办法强制UIAlertView调整自己的大小以适应?

相关的代码是在这里

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free Update",nil) 
               message:NSLocalizedString(@"There is a new version of this app available in the App Store. Download it now.",nil) 
               delegate:self 
             cancelButtonTitle:NSLocalizedString(@"Don't remind me",nil) 
             otherButtonTitles:NSLocalizedString(@"Download",nil), NSLocalizedString(@"Remind me later", nil), nil]; 
[alert show]; 
[alert release]; 

这是结果:

enter image description here

+0

您如何使用操作表?它总是显示标题,它意在用于采取行动。警报视图有很多缺陷(不是实现,而是设计),我谨慎使用它们。 –

+0

参见:http://stackoverflow.com/questions/7901834/uialertview-with-3-buttons-hides-message-in-landscape-mode – 2011-11-17 12:40:24

回答

0

最后,我们必须从警报视图中删除其中一个按钮,使其在横向模式下工作。

8

有点脏,但它的工作原理:O)只需添加一个UILabel到UIAlertView中

UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(alert.frame.origin.x + 10, 16, 260, 70)]; 
messageLabel.backgroundColor = [UIColor clearColor]; 
messageLabel.text = @"Your message"; 
messageLabel.textColor = [UIColor whiteColor]; 
messageLabel.lineBreakMode = UILineBreakModeWordWrap; 
messageLabel.numberOfLines = 2; 
messageLabel.font = [UIFont systemFontOfSize:12]; 
messageLabel.textAlignment = UITextAlignmentCenter; 
[alert addSubview:messageLabel]; 

另一个肮脏的黑客得到更多的标题和按钮之间的空间。

- (void)willPresentAlertView:(UIAlertView *)alertView { 
    float moreSpace = 20.0f; 

    alertView.frame = CGRectMake(alertView.frame.origin.x, alertView.frame.origin.y - moreSpace 
          ,alertView.frame.size.width, alertView.frame.size.height + moreSpace*2 + 10.0f); 

    for (UIView *view in [alertView subviews]) { 
     if ((view.class != UILabel.class) && (view.class != UIImageView.class)) { 
      [view setTransform:CGAffineTransformMakeTranslation(0, moreSpace * 2)]; 
     } 
    } 
} 
相关问题