2011-11-09 39 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)]; 
     } 
    } 
} 
相關問題