iOS Developer Library

Developer

UIKit Framework Reference NSParagraphStyle Class Reference

Options
Deployment Target:

On This Page
Language:

NSParagraphStyle

The NSParagraphStyle class and its subclass NSMutableParagraphStyle encapsulate the paragraph or ruler attributes used by the NSAttributedString classes. Instances of these classes are often referred to as paragraph style objects or, when no confusion will result, paragraph styles.

The mutable subclass of NSParagraphStyle is NSMutableParagraphStyle.

Inheritance


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later.
  • Returns the default paragraph style.

    Declaration

    Swift

    class func defaultParagraphStyle() -> NSParagraphStyle

    Objective-C

    + (NSParagraphStyle *)defaultParagraphStyle

    Discussion

    The default paragraph style has the following default values:

    Subattribute

    Default Value

    Alignment

    NSNaturalTextAlignment

    Tab stops (Mac OS X only)

    12 left-aligned tabs, spaced by 28.0 points

    Line break mode

    NSLineBreakByWordWrapping

    All others

    0.0

    See individual method descriptions for explanations of each subattribute.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • alignment alignment Property

    The text alignment of the receiver. (read-only)

    Declaration

    Swift

    var alignment: NSTextAlignment { get }

    Objective-C

    @property(readonly) NSTextAlignment alignment

    Discussion

    Natural text alignment is realized as left or right alignment depending on the line sweep direction of the first script contained in the paragraph.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The indentation of the first line of the receiver. (read-only)

    Declaration

    Swift

    var firstLineHeadIndent: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat firstLineHeadIndent

    Discussion

    This property contains the distance (in points) from the leading margin of a text container to the beginning of the paragraph’s first line. This value is always nonnegative.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The indentation of the receiver’s lines other than the first. (read-only)

    Declaration

    Swift

    var headIndent: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat headIndent

    Discussion

    This property contains the distance (in points) from the leading margin of a text container to the beginning of lines other than the first. This value is always nonnegative.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The trailing indentation of the receiver. (read-only)

    Declaration

    Swift

    var tailIndent: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat tailIndent

    Discussion

    If positive, this value is the distance from the leading margin (for example, the left margin in left-to-right text). If 0 or negative, it’s the distance from the trailing margin.

    For example, a paragraph style designed to fit exactly in a 2-inch wide container has a head indent of 0.0 and a tail indent of 0.0. One designed to fit with a quarter-inch margin has a head indent of 0.25 and a tail indent of –0.25.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The line height multiple. (read-only)

    Declaration

    Swift

    var lineHeightMultiple: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat lineHeightMultiple

    Discussion

    The natural line height of the receiver is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. 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 receiver’s maximum line height. (read-only)

    Declaration

    Swift

    var maximumLineHeight: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat maximumLineHeight

    Discussion

    This property contains the maximum height in points that any line in the receiver will occupy, regardless of the font size or size of any attached graphic. This value is always nonnegative. The default value is 0.

    Glyphs and graphics exceeding this height will overlap neighboring lines; however, a maximum height of 0 implies no line height limit. Although this limit applies to the line itself, line spacing adds extra space between adjacent lines.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The receiver’s minimum height. (read-only)

    Declaration

    Swift

    var minimumLineHeight: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat minimumLineHeight

    Discussion

    This property contains the minimum height in points that any line in the receiver will occupy, regardless of the font size or size of any attached graphic. This value is always nonnegative

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The distance in points between the bottom of one line fragment and the top of the next. (read-only)

    Declaration

    Swift

    var lineSpacing: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat lineSpacing

    Discussion

    This value is always nonnegative. This value is included in the line fragment heights in the layout manager.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The space after the end of the paragraph. (read-only)

    Declaration

    Swift

    var paragraphSpacing: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat paragraphSpacing

    Discussion

    This property contains the space (measured in points) added at the end of the paragraph to separate it from the following paragraph. This value is always nonnegative. The space between paragraphs is determined by adding the previous paragraph’s paragraphSpacing and the current paragraph’s paragraphSpacingBefore.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The distance between the paragraph’s top and the beginning of its text content. (read-only)

    Declaration

    Swift

    var paragraphSpacingBefore: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat paragraphSpacingBefore

    Discussion

    This property contains the space (measured in points) between the paragraph’s top and the beginning of its text content. 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.

    See Also

    paragraphSpacing

  • Returns the receiver’s tab stops.

    Declaration

    Swift

    var tabStops: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy, nonatomic) NSArray *tabStops

    Return Value

    The NSTextTab objects, sorted by location, that define the tab stops for the paragraph style.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • tabStops tabStops Property

    An array of NSTextTab objects representing the receiver’s tab stops.

    Declaration

    Swift

    var tabStops: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy, nonatomic) NSArray *tabStops

    Discussion

    The NSTextTab objects, sorted by location, define the tab stops for the paragraph style. Default value is nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the document-wide default tab interval.

    Declaration

    Swift

    var defaultTabInterval: CGFloat { get }

    Objective-C

    @property(readonly, nonatomic) CGFloat defaultTabInterval

    Return Value

    The default tab interval in points. Tabs after the last specified in tabStops are placed at integer multiples of this distance (if positive). Default return value is 0.0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The document-wide default tab interval.

    Declaration

    Swift

    var defaultTabInterval: CGFloat { get }

    Objective-C

    @property(readonly, nonatomic) CGFloat defaultTabInterval

    Discussion

    This property represents the default tab interval in points. Tabs after the last specified in tabStops are placed at integer multiples of this distance (if positive). Default value is 0.0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    tabStops

  • The mode that should be used to break lines in the receiver. (read-only)

    Declaration

    Swift

    var lineBreakMode: NSLineBreakMode { get }

    Objective-C

    @property(readonly) NSLineBreakMode lineBreakMode

    Discussion

    This property contains the line break mode to be used laying out the paragraph’s text.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The paragraph’s threshold for hyphenation. (read-only)

    Declaration

    Swift

    var hyphenationFactor: Float { get }

    Objective-C

    @property(readonly) float hyphenationFactor

    Discussion

    Hyphenation is attempted when the ratio of the text width (as broken without hyphenation) to the width of the line fragment is less than the hyphenation factor. When the paragraph’s hyphenation factor is 0.0, the layout manager’s hyphenation factor is used instead. When both are 0.0, hyphenation is disabled.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Returns the default writing direction for the specified language.

    Declaration

    Swift

    class func defaultWritingDirectionForLanguage(_ languageName: String?) -> NSWritingDirection

    Objective-C

    + (NSWritingDirection)defaultWritingDirectionForLanguage:(NSString *)languageName

    Parameters

    languageName

    The language specified in ISO language region format. Can be nil to return a default writing direction derived from the user’s defaults database.

    Return Value

    The default writing direction.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The base writing direction for the receiver. (read-only)

    Declaration

    Swift

    var baseWritingDirection: NSWritingDirection { get }

    Objective-C

    @property(readonly) NSWritingDirection baseWritingDirection

    Discussion

    If you the value of this property is NSWritingDirectionNaturalDirection, the receiver resolves the writing direction to either NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft, depending on the direction for the user’s language preference setting.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • These constants specify what happens when a line is too long for its container.

    Declaration

    Swift

    enum NSLineBreakMode : Int { case ByWordWrapping case ByCharWrapping case ByClipping case ByTruncatingHead case ByTruncatingTail case ByTruncatingMiddle }

    Objective-C

    enum { NSLineBreakByWordWrapping = 0, NSLineBreakByCharWrapping, NSLineBreakByClipping, NSLineBreakByTruncatingHead, NSLineBreakByTruncatingTail, NSLineBreakByTruncatingMiddle }; typedef NSUInteger NSLineBreakMode

    Constants

    • ByWordWrapping

      NSLineBreakByWordWrapping

      Wrapping occurs at word boundaries, unless the word itself doesn’t fit on a single line. See Characters and Grapheme Clusters in String Programming Guide for a discussion of issues related to determining word boundaries.

      Available in iOS 6.0 and later.

    • ByCharWrapping

      NSLineBreakByCharWrapping

      Wrapping occurs before the first character that doesn’t fit.

      Available in iOS 6.0 and later.

    • ByClipping

      NSLineBreakByClipping

      Lines are simply not drawn past the edge of the text container.

      Available in iOS 6.0 and later.

    • ByTruncatingHead

      NSLineBreakByTruncatingHead

      The line is displayed so that the end fits in the container and the missing text at the beginning of the line is indicated by an ellipsis glyph. Although this mode works for multiline text, it is more often used for single line text.

      Available in iOS 6.0 and later.

    • ByTruncatingTail

      NSLineBreakByTruncatingTail

      The line is displayed so that the beginning fits in the container and the missing text at the end of the line is indicated by an ellipsis glyph. Although this mode works for multiline text, it is more often used for single line text.

      Available in iOS 6.0 and later.

    • ByTruncatingMiddle

      NSLineBreakByTruncatingMiddle

      The line is displayed so that the beginning and end fit in the container and the missing text in the middle is indicated by an ellipsis glyph. Although this mode works for multiline text, it is more often used for single line text.

      Available in iOS 6.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.