Deprecated NSString UIKit Additions Methods

A method identified as deprecated has been superseded and may become unsupported in the future.

Deprecated in iOS 7.0

drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:

Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes. (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)

- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font fontSize:(CGFloat)fontSize lineBreakMode:(NSLineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment
Parameters
point

The location (in the coordinate system of the current graphics context) at which to draw the string. This point represents the top-left corner of the string’s bounding box.

width

The maximum width of the string.

font

The font to use for rendering.

fontSize

The font size to use instead of the one associated with the font object in the font parameter.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

baselineAdjustment

Specifies the vertical text-adjustment rule to use. This rule is used to determine the position of the text in cases where the text must be drawn at a smaller size.

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Discussion

This method draws only a single line of text, drawing as much of the string as possible using the given font and constraints. This method does not perform any line wrapping during drawing.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

drawAtPoint:forWidth:withFont:lineBreakMode:

Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes. (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)

- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode
Parameters
point

The location (in the coordinate system of the current graphics context) at which to draw the string. This point represents the top-left corner of the string’s bounding box.

width

The maximum width of the string.

font

The font to use for rendering.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Discussion

This method draws only a single line of text, drawing as much of the string as possible using the given font and constraints. This method does not perform any line wrapping during drawing.

If the value in the width parameter is smaller than actual width of the string, truncation may occur. In that situation, the options in the lineBreakMode parameter determine where to end the text.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

drawAtPoint:forWidth:withFont:minFontSize:actualFontSize:lineBreakMode:baselineAdjustment:

Draws the string in a single line with the specified font and attributes, adjusting the font attributes as needed to render as much of the text as possible. (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)

- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize lineBreakMode:(NSLineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment
Parameters
point

The location (in the coordinate system of the current graphics context) at which to draw the string. This point represents the top-left corner of the string’s bounding box.

width

The maximum width of the string.

font

The font to use for rendering.

minFontSize

The minimum size to which the font may be reduced before resorting to truncation of the text.

actualFontSize

On input, a pointer to a floating-point value. On return, this value contains the actual font size that was used to render the string.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

baselineAdjustment

Specifies the vertical text-adjustment rule to use. This rule is used to determine the position of the text in cases where the text must be drawn at a smaller size.

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

drawAtPoint:withFont:

Draws the string in a single line at the specified point in the current graphics context using the specified font. (Deprecated in iOS 7.0. Use drawAtPoint:withAttributes: instead.)

- (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font
Parameters
point

The location (in the coordinate system of the current graphics context) at which to draw the string. This point represents the top-left corner of the string’s bounding box.

font

The font to use for rendering.

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Discussion

This method draws only a single line of text, drawing as much of the string as possible using the given font. This method does not perform any line wrapping during drawing.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

drawInRect:withFont:

Draws the string in the current graphics context using the specified bounding rectangle and font. (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font
Parameters
rect

The bounding rectangle (in the current graphics context) in which to draw the string.

font

The font to use for rendering.

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Discussion

This method draws as much of the string as possible using the given font and constraints. This method uses the UILineBreakModeWordWrap line break mode and the UITextAlignmentLeft alignment.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Related Sample Code
Declared In
UIStringDrawing.h

drawInRect:withFont:lineBreakMode:

Draws the string in the current graphics context using the specified bounding rectangle, font, and attributes. (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode
Parameters
rect

The bounding rectangle (in the current graphics context) in which to draw the string.

font

The font to use for rendering.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Discussion

This method draws as much of the string as possible using the given font, line break mode, and size constraints. The text is drawn using the UITextAlignmentLeft alignment.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

drawInRect:withFont:lineBreakMode:alignment:

Draws the string in the current graphics context using the specified bounding rectangle, font and attributes. (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment
Parameters
rect

The bounding rectangle (in the current graphics context) in which to draw the string.

font

The font to use for rendering.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

alignment

The alignment of the text inside the bounding rectangle. For a list of possible values, see “UITextAlignment.”

Return Value

The size of the rendered string. The returned values may be rounded up to the nearest whole number.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

sizeWithFont:

Returns the size of the string if it were to be rendered with the specified font on a single line. (Deprecated in iOS 7.0. Use sizeWithAttributes: instead.)

- (CGSize)sizeWithFont:(UIFont *)font
Parameters
font

The font to use for computing the string size.

Return Value

The width and height of the resulting string’s bounding box. These values may be rounded up to the nearest whole number.

Discussion

You can use this method to obtain the layout metrics you need to draw a string in your user interface. This method does not actually draw the string or alter the receiver’s text in any way.

In iOS 6, this method wraps text using the NSLineBreakByWordWrapping option by default. In earlier versions of iOS, this method does not perform any line wrapping and returns the absolute width and height of the string using the specified font.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

sizeWithFont:constrainedToSize:

Returns the size of the string if it were rendered and constrained to the specified size. (Deprecated in iOS 7.0. Use boundingRectWithSize:options:attributes:context: instead. See also UILabel as a possible alternative for some use cases.)

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size
Parameters
font

The font to use for computing the string size.

size

The maximum acceptable size for the string. This value is used to calculate where line breaks and wrapping would occur.

Return Value

The width and height of the resulting string’s bounding box. These values may be rounded up to the nearest whole number.

Discussion

You can use this method to obtain the layout metrics you need to draw a string in your user interface. This method does not actually draw the string or alter the receiver’s text in any way.

This method computes the metrics needed to draw the specified string. This method lays out the receiver’s text and attempts to make it fit the specified size using the specified font and the NSLineBreakByWordWrapping line break option. During layout, the method may break the text onto multiple lines to make it fit better. If the receiver’s text does not completely fit in the specified size, it lays out as much of the text as possible and truncates it (for layout purposes only) according to the specified line break mode. It then returns the size of the resulting truncated string. If the height specified in the size parameter is less than a single line of text, this method may return a height value that is bigger than the one specified.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

sizeWithFont:constrainedToSize:lineBreakMode:

Returns the size of the string if it were rendered with the specified constraints. (Deprecated in iOS 7.0. Use boundingRectWithSize:options:attributes:context: instead.)

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode
Parameters
font

The font to use for computing the string size.

size

The maximum acceptable size for the string. This value is used to calculate where line breaks and wrapping would occur.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

Return Value

The width and height of the resulting string’s bounding box. These values may be rounded up to the nearest whole number.

Discussion

You can use this method to obtain the layout metrics you need to draw a string in your user interface. This method does not actually draw the string or alter the receiver’s text in any way.

This method computes the metrics needed to draw the specified string. This method lays out the receiver’s text and attempts to make it fit the specified size using the specified font and line break options. During layout, the method may break the text onto multiple lines to make it fit better. If the receiver’s text does not completely fit in the specified size, it lays out as much of the text as possible and truncates it (for layout purposes only) according to the specified line break mode. It then returns the size of the resulting truncated string. If the height specified in the size parameter is less than a single line of text, this method may return a height value that is bigger than the one specified.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

sizeWithFont:forWidth:lineBreakMode:

Returns the size of the string if it were to be rendered with the specified font and line attributes on a single line. (Deprecated in iOS 7.0. Use boundingRectWithSize:options:attributes:context:.)

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(NSLineBreakMode)lineBreakMode
Parameters
font

The font to use for computing the string size.

width

The maximum acceptable width for the string. This value is used to calculate where line breaks would be placed.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

Return Value

The width and height of the resulting string’s bounding box. These values may be rounded up to the nearest whole number.

Discussion

You can use this method to obtain the layout metrics you need to draw a string in your user interface. This method does not actually draw the string or alter the receiver’s text in any way.

This method returns the width and height of the string constrained to the specified width. Although it computes where line breaks would occur, this method does not actually wrap the text to additional lines. If the size of the string exceeds the given width, this method truncates the text (for layout purposes only) using the specified line break mode until it does conform to the maximum width; it then returns the size of the resulting truncated string.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h

sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

Returns the size of the string if it were rendered with the specified constraints, including a variable font size, on a single line. (Deprecated in iOS 7.0. There is no exact alternative for this method. Human interface guidelines discourage changing the font size this way because it leads to an inconsistent user experience. See UILabel as a possible alternative for some use cases.)

- (CGSize)sizeWithFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize forWidth:(CGFloat)width lineBreakMode:(NSLineBreakMode)lineBreakMode
Parameters
font

The font to use for computing the string size.

minFontSize

The minimum size to which the font may be reduced before resorting to truncation of the text.

actualFontSize

On input, a pointer to a floating-point value. On return, this value contains the actual font size that was used to compute the size of the string.

width

The maximum acceptable width for the string. This value is used to calculate where line breaks would be placed.

lineBreakMode

The line break options for computing the size of the string. For a list of possible values, see NSLineBreakMode.

Return Value

The width and height of the resulting string’s bounding box. These values may be rounded up to the nearest whole number.

Discussion

You can use this method to obtain the layout metrics you need to draw a string in your user interface. This method does not actually draw the string or alter the receiver’s text in any way.

Although it computes where line breaks would occur, this method does not actually wrap the text to additional lines. If the entire string does not fit within the given width using the initial font size, this method reduces the font size until the string does fit or until it reaches the specified minimum font size. If it reaches the minimum font size, the method begins truncating the text (for layout purposes only) until the resulting truncated string does fit the width; it then then returns the size of that truncated string.

Availability
  • Available in iOS 2.0 and later.
  • Deprecated in iOS 7.0.
Declared In
UIStringDrawing.h