iOS Developer Library

Developer

UIKit Framework Reference NSStringDrawingContext Class Reference

Options
Deployment Target:

On This Page
Language:

NSStringDrawingContext

Inherits From


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later

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.

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

    Declaration

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 6.0 and later

    Deprecated in iOS 7.0

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

    Declaration

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 6.0 and later

    Deprecated in iOS 7.0

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

    Declaration

    Swift

    var minimumScaleFactor: CGFloat

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

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

    Declaration

    Swift

    var actualScaleFactor: CGFloat { get }

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

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

    Declaration

    Swift

    var totalBounds: CGRect { get }

    Objective-C

    @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.)

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later