¿Es posible obtener el tamaño de fuente final, después del autoajuste? (La propiedad ajustaFetSizeToFitWidth se establece en YES, y el tamaño de la fuente de texto se está reduciendo para encajar en la etiqueta)¿Cómo obtener UILabel (UITextView) tamaño de letra ajustado automáticamente?
Estoy subclasando drawTextInRect en UILabel para poner degradado en el texto, pero el tamaño del degradado debe ser el mismo, como el tamaño de la fuente. No puedo obtener el tamaño correcto de la fuente ajustada ... ¿Es posible?
//draw gradient
CGContextSaveGState(myContext);
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1, 1, 1, 0.25, // BOTTOM color
1, 1, 1, 0.12 }; // UPPER color
//scale and translate so that text would not be rotated 180 deg wrong
CGContextTranslateCTM(myContext, 0, rect.size.height);
CGContextScaleCTM(myContext, 1.0, -1.0);
//create mask
CGImageRef alphaMask = CGBitmapContextCreateImage(myContext);
CGContextClipToMask(myContext, rect, alphaMask);
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
//gradient should be sized to actual font size. THIS IS THE PROBLEM - EVEN IF FONT IS AUTO ADUJSTED, I AM GETTING THE SAME ORIGINAL FONT SIZE!!!
CGFloat fontCapHeightHalf = (self.font.capHeight/2)+5;
CGRect currentBounds = rect;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds)-fontCapHeightHalf);
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds)+fontCapHeightHalf);
CGContextDrawLinearGradient(myContext, glossGradient, topCenter, midCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
CGContextRestoreGState(myContext);
posible duplicado de [Cómo calcular el tamaño de un UIFont cuando el texto de la etiqueta está limitado hacia abajo para adaptarse a la anchura?] (Http: // stackoverflow.com/questions/1385338/how-to-calculate-the-size-of-a-uifont-when-text-in-label-is-constrained-down-to-f) –
sí, gracias por señalarme la dirección correcta. No lo encontré antes de publicar mi pregunta. –