iOS Developer Library

Developer

UIKit Framework Reference NSString UIKit Additions Reference

Options
Deployment Target:

On This Page
Language:

NSString

The UIKit framework adds methods to NSString to support the drawing of strings and to compute the bounding box of a string prior to drawing. None of these methods affects the contents of the string object itself, only how it is drawn on screen. More...

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 2.0 and later.
  • Returns the size of the string if it were to be rendered with the specified font on a single line.

    Deprecation Statement

    Use sizeWithAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Returns the size of the string if it were to be rendered with the specified font and line attributes on a single line.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Returns the size of the string if it were rendered with the specified constraints, including a variable font size, on a single line.

    Deprecation Statement

    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.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Returns the size of the string if it were rendered and constrained to the specified size.

    Deprecation Statement

    Use boundingRectWithSize:options:attributes:context: instead. See also UILabel as a possible alternative for some use cases.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Returns the size of the string if it were rendered with the specified constraints.

    Deprecation Statement

    Use boundingRectWithSize:options:attributes:context: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Draws the string in a single line at the specified point in the current graphics context using the specified font.

    Deprecation Statement

    Use drawAtPoint:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes.

    Deprecation Statement

    Use drawInRect:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes.

    Deprecation Statement

    Use drawInRect:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

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

    Deprecation Statement

    Use drawInRect:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Draws the receiver with the font and other display characteristics of the given attributes, at the specified point in the current graphics context.

    Declaration

    Swift

    func drawAtPoint(_ point: CGPoint, withAttributes attrs: [NSObject : AnyObject]?)

    Objective-C

    - (void)drawAtPoint:(CGPoint)point withAttributes:(NSDictionary *)attrs

    Parameters

    point

    The point in the current graphics context where you want to start drawing the string. The coordinate system of the graphics context is usually defined by the view in which you are drawing.

    attrs

    A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string.

    Discussion

    The width (height for vertical layout) of the rendering area is unlimited, unlike drawInRect:withAttributes:, which uses a bounding rectangle. As a result, this method renders the text in a single line. However, if newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Draws the string in the current graphics context using the specified bounding rectangle and font.

    Deprecation Statement

    Use drawInRect:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Draws the string in the current graphics context using the specified bounding rectangle, font, and attributes.

    Deprecation Statement

    Use drawInRect:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Draws the string in the current graphics context using the specified bounding rectangle, font and attributes.

    Deprecation Statement

    Use drawInRect:withAttributes: instead.

    Declaration

    Objective-C

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context.

    Declaration

    Swift

    func boundingRectWithSize(_ size: CGSize, options options: NSStringDrawingOptions, attributes attributes: [NSObject : AnyObject]!, context context: NSStringDrawingContext!) -> CGRect

    Objective-C

    - (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context

    Parameters

    size

    The size of the rectangle to draw in.

    options

    String drawing options.

    attributes

    A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string.

    context

    The string drawing context to use for the receiver, specifying minimum scale factor and tracking adjustments.

    Return Value

    The bounding rect for the receiver drawn using the given options and display characteristics. The rect origin returned from this method is the first glyph origin.

    Discussion

    To correctly draw and size multi-line text, pass NSStringDrawingUsesLineFragmentOrigin in the options parameter.

    This method returns fractional sizes (in the size component of the returned CGRect); to use a returned size to size views, you must raise its value to the nearest higher integer using the ceil function.

    This method returns the actual bounds of the glyphs in the string. Some of the glyphs (spaces, for example) are allowed to overlap the layout constraints specified by the size passed in, so in some cases the width value of the size component of the returned CGRect can exceed the width value of the size parameter.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Draws the attributed string inside the specified bounding rectangle in the current graphics context.

    Declaration

    Swift

    func drawInRect(_ rect: CGRect, withAttributes attrs: [NSObject : AnyObject]?)

    Objective-C

    - (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs

    Parameters

    rect

    The bounding rectangle in which to draw the string.

    attrs

    The text attributes with which to draw the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string.

    Discussion

    This method draws as much of the string as it can inside the specified rectangle, wrapping the string text as needed to make it fit. If the string is too long to fit inside the rectangle, the method renders as much as possible and clips the rest.

    If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Draws the attributed string in the specified bounding rectangle using the provided options.

    Declaration

    Swift

    func drawWithRect(_ rect: CGRect, options options: NSStringDrawingOptions, attributes attributes: [NSObject : AnyObject]!, context context: NSStringDrawingContext!)

    Objective-C

    - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context

    Parameters

    rect

    The bounding rectangle in which to draw the string.

    options

    Additional drawing options to apply to the string during rendering. For a list of possible values, see NSStringDrawingOptions.

    attributes

    The text attributes with which to draw the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string.

    context

    A context object with information about how to adjust the font tracking and scaling information. On return, the specified object contains information about the actual values used to render the string. This parameter may be nil.

    Discussion

    This method draws as much of the string as it can inside the specified rectangle, wrapping the string text as needed to make it fit. If the string is too big to fit completely inside the rectangle, the method scales the font or adjusts the letter spacing to make the string fit within the given bounds.

    If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point. To correctly draw and size multi-line text, pass NSStringDrawingUsesLineFragmentOrigin in the options parameter.

    Special Considerations

    This method uses the baseline origin by default.

    If NSStringDrawingUsesLineFragmentOrigin is not specified, the rectangle’s height will be ignored and the operation considered to be single-line rendering.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the bounding box size the receiver occupies when drawn with the given attributes.

    Declaration

    Swift

    func sizeWithAttributes(_ attrs: [NSObject : AnyObject]?) -> CGSize

    Objective-C

    - (CGSize)sizeWithAttributes:(NSDictionary *)attrs

    Parameters

    attrs

    A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string.

    Return Value

    The bounding box size the receiver occupies when drawn with the specified attributes.

    Discussion

    This method returns fractional sizes; to use a returned size to size views, you must raise its value to the nearest higher integer using the ceil function.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Options for wrapping and truncating text.

    Use NSLineBreakMode instead.

    Declaration

    Objective-C

    typedef enum { UILineBreakModeWordWrap = 0, UILineBreakModeCharacterWrap, UILineBreakModeClip, UILineBreakModeHeadTruncation, UILineBreakModeTailTruncation, UILineBreakModeMiddleTruncation, } UILineBreakMode;

    Constants

    • UILineBreakModeWordWrap

      UILineBreakModeWordWrap

      Wrap or clip the string only at word boundaries. This is the default wrapping option.

      Use NSLineBreakByWordWrapping instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UILineBreakModeCharacterWrap

      UILineBreakModeCharacterWrap

      Wrap or clip the string at the closest character boundary.

      Use NSLineBreakByCharWrapping instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UILineBreakModeClip

      UILineBreakModeClip

      Clip the text when the end of the drawing rectangle is reached. This option could result in a partially rendered character at the end of a string.

      Use NSLineBreakByClipping instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UILineBreakModeHeadTruncation

      UILineBreakModeHeadTruncation

      Truncate text (as needed) from the beginning of the line. For multiple lines of text, only text on the first line is truncated.

      Use NSLineBreakByTruncatingHead instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UILineBreakModeTailTruncation

      UILineBreakModeTailTruncation

      Truncate text (as needed) from the end of the line. For multiple lines of text, only text on the last line is truncated.

      Use NSLineBreakByTruncatingTail instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UILineBreakModeMiddleTruncation

      UILineBreakModeMiddleTruncation

      Truncate text (as needed) from the middle of the line. For multiple lines of text, text is truncated only at the midpoint of the line.

      Use NSLineBreakByTruncatingMiddle instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    Discussion

    For methods that draw at a specified point (as opposed to those that draw in a rectangular region), these options specify the clipping behavior that is applied to the string.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • Options for aligning text horizontally.

    Declaration

    Swift

    enum NSTextAlignment : Int { case Left case Center case Right case Justified case Natural }

    Objective-C

    enum { NSTextAlignmentLeft = 0, NSTextAlignmentCenter = 1, NSTextAlignmentRight = 2, NSTextAlignmentJustified = 3, NSTextAlignmentNatural = 4, }; typedef NSInteger NSTextAlignment;

    Constants

    • Left

      NSTextAlignmentLeft

      Align text along the left edge.

      Available in iOS 6.0 and later.

    • Center

      NSTextAlignmentCenter

      Align text equally along both sides of the center line.

      Available in iOS 6.0 and later.

    • Right

      NSTextAlignmentRight

      Align text along the right edge.

      Available in iOS 6.0 and later.

    • Justified

      NSTextAlignmentJustified

      Fully justify the text so that the last line in a paragraph is natural aligned.

      Available in iOS 6.0 and later.

    • Natural

      NSTextAlignmentNatural

      Use the default alignment associated with the current script.

      Available in iOS 6.0 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Options for aligning text horizontally.

    Use “NSTextAlignment” instead.

    Declaration

    Objective-C

    typedef enum { UITextAlignmentLeft, UITextAlignmentCenter, UITextAlignmentRight, } UITextAlignment;

    Constants

    • UITextAlignmentLeft

      UITextAlignmentLeft

      Align text along the left edge.

      Use NSTextAlignmentLeft instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UITextAlignmentCenter

      UITextAlignmentCenter

      Align text equally along both sides of the center line.

      Use NSTextAlignmentCenter instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    • UITextAlignmentRight

      UITextAlignmentRight

      Align text along the right edge.

      Use NSTextAlignmentRight instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 6.0.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • Vertical adjustment options.

    Declaration

    Swift

    enum UIBaselineAdjustment : Int { case AlignBaselines case AlignCenters case None }

    Objective-C

    typedef enum { UIBaselineAdjustmentAlignBaselines, UIBaselineAdjustmentAlignCenters, UIBaselineAdjustmentNone, } UIBaselineAdjustment;

    Constants

    • AlignBaselines

      UIBaselineAdjustmentAlignBaselines

      Adjust text relative to the position of its baseline.

      Available in iOS 2.0 and later.

    • AlignCenters

      UIBaselineAdjustmentAlignCenters

      Adjust text based relative to the center of its bounding box.

      Available in iOS 2.0 and later.

    • None

      UIBaselineAdjustmentNone

      Adjust text relative to the top-left corner of the bounding box. This is the default adjustment.

      Available in iOS 2.0 and later.

    Discussion

    Baseline adjustment options determine how to adjust the position of text in cases where the text must be drawn using a different font size than the one originally specified. For example, with the UIBaselineAdjustmentAlignBaselines option, the position of the baseline remains fixed at its initial location while the text appears to move toward that baseline. Similarly, the UIBaselineAdjustmentNone option makes it appear as if the text is moving upwards towards the top-left corner of the bounding box.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Constants for specifying the writing direction to use.

    Declaration

    Swift

    enum NSWritingDirection : Int { case Natural case LeftToRight case RightToLeft }

    Objective-C

    enum { NSWritingDirectionNatural = -1, NSWritingDirectionLeftToRight = 0, NSWritingDirectionRightToLeft = 1 }; typedef NSInteger NSWritingDirection;

    Constants

    • Natural

      NSWritingDirectionNatural

      Use the Unicode Bidi algorithm rules P2 and P3 to determine which direction to use.

      Available in iOS 6.0 and later.

    • LeftToRight

      NSWritingDirectionLeftToRight

      Use a left to right writing direction.

      Available in iOS 6.0 and later.

    • RightToLeft

      NSWritingDirectionRightToLeft

      Use a right to left writing direction.

      Available in iOS 6.0 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Keys for dictionaries that contain text attributes.

    Declaration

    Objective-C

    NSString *const UITextAttributeFont; NSString *const UITextAttributeTextColor; NSString *const UITextAttributeTextShadowColor; NSString *const UITextAttributeTextShadowOffset;

    Constants

    • UITextAttributeFont

      UITextAttributeFont

      Key to the font in a text attributes dictionary.

      The corresponding value is an instance of UIFont.

      Use a font with size 0.0 to get the default font size for the current context.

      Available in iOS 5.0 and later.

      Deprecated in iOS 7.0.

    • UITextAttributeTextColor

      UITextAttributeTextColor

      Key to the text color in a text attributes dictionary.

      The corresponding value is an instance of UIColor.

      Available in iOS 5.0 and later.

      Deprecated in iOS 7.0.

    • UITextAttributeTextShadowColor

      UITextAttributeTextShadowColor

      Key to the text shadow color in a text attributes dictionary.

      The corresponding value is an instance of UIColor.

      Available in iOS 5.0 and later.

      Deprecated in iOS 7.0.

    • UITextAttributeTextShadowOffset

      UITextAttributeTextShadowOffset

      Key to the offset used for the text shadow in a text attributes dictionary.

      The corresponding value is an instance of NSValue wrapping a UIOffset struct.

      Available in iOS 5.0 and later.

      Deprecated in iOS 7.0.

    Import Statement