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, alloc/init 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

actualTrackingAdjustment

The actual tracking value that was applied during drawing. (read-only)

@property(nonatomic, readonly) CGFloat actualTrackingAdjustment
Discussion

If you specified a custom value in the minimumTrackingAdjustment property, when drawing is complete, this property contains the actual tracking value that was used.

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

minimumTrackingAdjustment

The smallest amount of space (in points) to maintain between characters.

@property(nonatomic) CGFloat minimumTrackingAdjustment
Discussion

Changing the value of this property tells the renderer that it can change the tracking to a value no smaller than the indicated amount. For example, a value of -0.5 indicates that characters can be tracked closer together by up to half a point. A value of 0 indicates that the standard spacing is used. A typical range of values for this property would be -0.5 to 0.0. 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 view where the string was drawn.

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

Did this document help you? Yes It's good, but... Not helpful...