Wie wird die Schriftgröße von UILabel (UITextView) automatisch angepasst?

Ist es möglich, nach dem automatischen Anpassen die endgültige Schriftgröße zu erhalten? (Die Eigenschaft adjustsFontSizeToFitWidth wurde auf YES gesetzt, und die Schriftgröße des Texts wird verkleinert, um in die Beschriftung zu passen.)

Ich untergeordnete Klasse "drawTextInRect" in UILabel, um den Text mit einem Farbverlauf zu versehen. Die Größe des Farbverlaufs muss jedoch mit der Größe der Schriftart übereinstimmen. Ich kann die angepasste Schriftgröße nicht richtig ermitteln ... Ist das überhaupt möglich?

  //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);

Antworten auf die Frage(6)

Ihre Antwort auf die Frage