NSStringDrawingContext Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 6.0 and later.
Declared in
NSStringDrawing.h

Overview

The NSStringDrawingContext class manages metrics used when drawing attributed strings. Prior to drawing, you can create an instance of this class and use it to specify the minimum scale factor and tracking adjustments for a string. After drawing, you can retrieve the actual values that were used during drawing.

To use this class, allocate and initialize a new instance, set the minimum values, and pass your object to one of the corresponding NSAttributedString methods that take the context object as a parameter. Upon completion of drawing, you can use the actual drawing values to make adjustments or record where the string was actually drawn.

Tasks

Accessing the Tracking Adjustments

Accessing the Scale Factors

Getting the Drawing Bounds

Properties

actualScaleFactor

The actual scale factor that was applied to the font during drawing. (read-only)

@property(nonatomic, readonly) CGFloat actualScaleFactor
Discussion

If you specified a custom value in the minimumScaleFactor property, when drawing is complete, this property contains the actual scale factor value that was used to draw the string.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

minimumScaleFactor

The scale factor that determines the smallest font size to use during drawing.

@property(nonatomic) CGFloat minimumScaleFactor
Discussion

A value of 0.0 corresponds to a scale factor of 1.0. Any value greater than 0.0 is multiplied by the font point size to get the smallest font size that is permissible to use. For example, 0.5 indicates a font that is half the size of the actual font, 0.75 is three-quarters of the font size, and so on. Typically, you specify a value between 0.0 and 1.0 to indicate how much the font can be shrunk during drawing.

The default value of this property is 0.0.

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h

totalBounds

The bounding rectangle that was last used when drawing the string. (read-only)

@property(nonatomic, readonly) CGRect totalBounds
Discussion

This property contains the bounding rectangle that was last used when calling the drawWithRect:options:context: method. The rectangle is specified in the coordinate system of the drawn string. (The origin of the bounds corresponds to neither a view the string might have been drawn into nor the origin of a possible drawInRect: call.)

Availability
  • Available in iOS 6.0 and later.
Declared In
NSStringDrawing.h