Tengo un NSString, y quiero saber su altura para crear un UILabel apropiado.Obtener la altura NSString
Haciendo esta altura
NSString *string = @"this is an example";
CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:10.0f]
forWidth:353.0
lineBreakMode:UILineBreakModeWordWrap];
float height = size.height;
es ahora 13,0. Si utilizo esta cadena
NSString *string = @"this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example ";
altura es siempre 13,0 (y con 353 como el ancho, eso es imposible) ... ¿qué estoy haciendo mal?
ADD:
size.width;
funciona bien ... así que es como si el lineBreakMode no es correcto ... pero es, ¿verdad?
Estás tomando que el tamaño de la cadena. objeto, no el CGSize que acaba de crear. ¿Es eso un error tipográfico? –
pero 'sizeWithFont: forWidth: lineBreakMode' toma un NSString (no un UILabel, por ejemplo) ... así que es correcto ... ¿o no? – JAA
No lo toma, por ejemplo, actúa sobre él y le devuelve un tamaño. Entonces, si tuviera que cambiar 'float height = string.height;' a 'float height = size.altura; ', supongo que tendrá más sentido. –