问题
Possible Duplicate:
UIAlertView not showing message text
I am trying to create a simple UIAlertView for an app in landscape mode but all I see is the title and buttons but no actual message.
It has something to do with the space available for the UIAlertView on the screen as if I remove a couple of the buttons then the message displays fine.
Is there a way to force the UIAlertView to resize itself to fit?
Relevant code is here
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];
And this is the result:
回答1:
a bit dirty but it works :o) just add a UILabel to the 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];
another dirty hack to get more space between title and buttons.
- (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)];
}
}
}
回答2:
In the end we had to drop one of the buttons from the alert view to make it work in landscape mode.
来源:https://stackoverflow.com/questions/8059297/uialertview-in-landscape-mode-does-not-display-message