Sé que esta es una vieja pregunta, pero estaba enfrentando el mismo problema y las respuestas aquí me ayudaron. Necesitaba agrandar los campos de título y texto del mensaje para acomodar más texto en el iPad.
Lo que hice fue implementar el método delegado UIAlertView willPresentAlertView: y agregar dos objetos UILabel para servir como título y mensaje. Fui capaz de configurar el tamaño del marco y el origen de estas dos etiquetas. Después de obtener el tamaño deseado para los campos de texto, cambio el tamaño de la vista de alerta para acomodar el nuevo texto. Luego repito las subvistas de la vista de alertas para encontrar el botón y ajustar su marco.
- (void)willPresentAlertView:(UIAlertView *)alertView {
// add a new label and configure it to replace the title
UILabel *tempTitle = [[UILabel alloc] initWithFrame:CGRectMake(10,20,350, 20)];
tempTitle.backgroundColor = [UIColor clearColor];
tempTitle.textColor = [UIColor whiteColor];
tempTitle.textAlignment = UITextAlignmentCenter;
tempTitle.numberOfLines = 1;
tempTitle.font = [UIFont boldSystemFontOfSize:18];
tempTitle.text = alertView.title;
alertView.title = @"";
[alertView addSubview:tempTitle];
[tempTitle release];
// add another label to use as message
UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 350, 200)];
tempLabel.backgroundColor = [UIColor clearColor];
tempLabel.textColor = [UIColor whiteColor];
tempLabel.textAlignment = UITextAlignmentCenter;
tempLabel.numberOfLines = 20;
tempLabel.text = alertView.message;
[alertView addSubview:tempLabel];
// method used to resize the height of a label depending on the text height
[self setUILabel:tempLabel withMaxFrame:CGRectMake(10,50, 350, 300) withText:alertView.message];
alertView.message = @"";
// set the frame of the alert view and center it
alertView.frame = CGRectMake(CGRectGetMinX(alertView.frame) - (370 - CGRectGetWidth(alertView.frame))/2 ,
alertView.frame.origin.y,
370,
tempLabel.frame.size.height + 120);
// iterate through the subviews in order to find the button and resize it
for(UIView *view in alertView.subviews)
{
if([[view class] isSubclassOfClass:[UIControl class]])
{
view.frame = CGRectMake (view.frame.origin.x+2,
tempLabel.frame.origin.y + tempLabel.frame.size.height + 10,
370 - view.frame.origin.x *2-4,
view.frame.size.height);
}
}
[tempLabel release];
}
y el método utilizado para cambiar el tamaño de la etiqueta:
- (void)setUILabel:(UILabel *)myLabel withMaxFrame:(CGRect)maxFrame withText:(NSString *)theText{
CGSize stringSize = [theText sizeWithFont:myLabel.font constrainedToSize:maxFrame.size lineBreakMode:myLabel.lineBreakMode];
myLabel.frame = CGRectMake(myLabel.frame.origin.x,
myLabel.frame.origin.y,
myLabel.frame.size.width,
stringSize.height
);
}
No sé si esta es la mejor manera de hacer esto, pero funcionó para mí.
¿Alguna vez encontrar una manera de hacer esto? Solo curiosidad, muchas respuestas aquí, hace tres años ... etc. – Morkrom