Mac Developer Library

Developer

AppKit Framework Reference NSTextContainer Class Reference

Options
Deployment Target:

On This Page
Language:

NSTextContainer

The NSTextContainer class defines a region where text is laid out. An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. NSTextContainer defines rectangular regions, but you can create subclasses that define regions of other shapes, such as circular regions, regions with holes in them, or regions that flow alongside graphics.

  • Initializes a text container with a specified bounding rectangle.

    Declaration

    Swift

    convenience init(containerSize aContainerSize: NSSize)

    Objective-C

    - (instancetype)initWithContainerSize:(NSSize)aSize

    Parameters

    aSize

    The size of the text container's bounding rectangle.

    Return Value

    The newly initialized text container.

    Discussion

    The new text container must be added to an NSLayoutManager object before it can be used. The text container must also have an NSTextView object set for text to be displayed. This method is the designated initializer for the NSTextContainer class.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.11.

    See Also

    – addTextContainer: (NSLayoutManager)
    textView

  • containerSize containerSize (OS X v10.11) Property

    The size of the receiver’s bounding rectangle.

    Declaration

    Swift

    var containerSize: NSSize

    Objective-C

    @property NSSize containerSize

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.11.

    See Also

    – setTextContainerInset: (NSTextView)

  • A Boolean that controls whether the receiver adjusts the width of its bounding rectangle when its text view is resized.

    Declaration

    Swift

    var widthTracksTextView: Bool

    Objective-C

    @property BOOL widthTracksTextView

    Discussion

    YEStrue if the receiver should follow changes to the width of its text view, NOfalse otherwise.

    See Text System Storage Layer Overview for more information on size tracking.

    Availability

    Available in OS X v10.0 and later.

  • A Boolean that controls whether the receiver adjusts the height of its bounding rectangle when its text view is resized.

    Declaration

    Swift

    var heightTracksTextView: Bool

    Objective-C

    @property BOOL heightTracksTextView

    Discussion

    YEStrue if the receiver should follow changes to the height of its text view, NOfalse otherwise.

    Availability

    Available in OS X v10.0 and later.

  • Overridden by subclasses to calculate and return the longest rectangle available in the proposed rectangle for displaying text, or NSZeroRect if there is none according to the receiver’s region definition.

    Declaration

    Swift

    func lineFragmentRectForProposedRect(_ proposedRect: NSRect, sweepDirection sweepDirection: NSLineSweepDirection, movementDirection movementDirection: NSLineMovementDirection, remainingRect remainingRect: NSRectPointer) -> NSRect

    Objective-C

    - (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect sweepDirection:(NSLineSweepDirection)sweepDirection movementDirection:(NSLineMovementDirection)movementDirection remainingRect:(NSRectPointer)remainingRect

    Parameters

    proposedRect

    The proposed rectangle in which to layout text.

    sweepDirection

    The line sweep direction.

    movementDirection

    The line movement direction.

    remainingRect

    Upon return, the unused, possibly shifted, portion of proposedRect that’s available for further text, or NSZeroRect if there is no remainder.

    Return Value

    The longest rectangle available in the proposed rectangle for displaying text, or NSZeroRect if there is none according to the receiver’s region definition.

    Discussion

    There is no guarantee as to the width of the proposed rectangle or to its location. For example, the proposed rectangle is likely to be much wider than the width of the receiver. The receiver should examine proposedRect to see that it intersects its bounding rectangle and should return a modified rectangle based on sweepDirection and movementDirection, whose possible values are listed in the class description. If sweepDirection is NSLineSweepRight, for example, the receiver uses this information to trim the right end of proposedRect as needed rather than the left end.

    If proposedRect doesn’t completely overlap the region along the axis of movementDirection and movementDirection isn’t NSLineDoesntMove, this method can either shift the rectangle in that direction as much as needed so that it does completely overlap, or return NSZeroRect to indicate that the proposed rectangle simply doesn’t fit.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.11.

  • A boolean that indicates whether the receiver’s region is a rectangle with no holes or gaps and whose edges are parallel to the text view's coordinate system axes. (read-only)

    Declaration

    Swift

    var simpleRectangularTextContainer: Bool { get }

    Objective-C

    @property(getter=isSimpleRectangularTextContainer, readonly) BOOL simpleRectangularTextContainer

    Discussion

    YEStrue if the receiver’s region is a rectangle with no holes or gaps and whose edges are parallel to the text view's coordinate system axes, NOfalse otherwise.

    The default NSTextContainer implementation of this method returns YEStrue.

    Availability

    Available in OS X v10.0 and later.

  • Overridden by subclasses to return whether a point lies within the receiver’s region or on the region’s edge—not simply within its bounding rectangle.

    Declaration

    Swift

    func containsPoint(_ point: NSPoint) -> Bool

    Objective-C

    - (BOOL)containsPoint:(NSPoint)aPoint

    Parameters

    aPoint

    The point in question.

    Return Value

    YEStrue if aPoint lies within the receiver’s region or on the region’s edge—not simply within its bounding rectangle—NOfalse otherwise.

    Discussion

    For example, if the receiver defines a donut shape and aPoint lies in the hole, this method returns NOfalse. This method can be used for hit testing of mouse events.

    The default NSTextContainer implementation merely checks that aPoint lies within its bounding rectangle.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.11.

  • These constants describe the progression of text on a page. The typesetter decides which way text is supposed to flow and passes these values as arguments to the text container, which uses them to calculate the next line rectangle.

    Declaration

    Swift

    enum NSLineSweepDirection : UInt { case Left case Right case Down case Up }

    Objective-C

    enum { NSLineSweepLeft = 0, NSLineSweepRight = 1, NSLineSweepDown = 2, NSLineSweepUp = 3 }; typedef NSUInteger NSLineSweepDirection;

    Constants

    • Left

      NSLineSweepLeft

      Characters move from right to left.

      Available in OS X v10.0 and later.

    • Right

      NSLineSweepRight

      Characters move from left to right.

      Available in OS X v10.0 and later.

    • Down

      NSLineSweepDown

      Characters move from top to bottom.

      Available in OS X v10.0 and later.

    • Up

      NSLineSweepUp

      Characters move from bottom to top.

      Available in OS X v10.0 and later.

    Discussion

    Line sweep is the direction text progresses within a line. See Text System Storage Layer Overview.

    The only values currently used by the supplied typesetters are NSLineSweepRight and NSLineMovesDown. An NSTextContainer subclass should be prepared to deal with any value, and an NSTypesetter subclass should be able to use any of them.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Line movement is the direction in which lines move. See Text System Storage Layer Overview.

    Declaration

    Swift

    enum NSLineMovementDirection : UInt { case DoesntMove case MovesLeft case MovesRight case MovesDown case MovesUp }

    Objective-C

    enum { NSLineDoesntMove = 0, NSLineMovesLeft = 1, NSLineMovesRight = 2, NSLineMovesDown = 3, NSLineMovesUp = 4 }; typedef NSUInteger NSLineMovementDirection;

    Constants

    • MovesLeft

      NSLineMovesLeft

      Lines move from right to left.

      Available in OS X v10.0 and later.

    • MovesRight

      NSLineMovesRight

      Lines move from left to right.

      Available in OS X v10.0 and later.

    • MovesDown

      NSLineMovesDown

      Lines move from top to bottom.

      Available in OS X v10.0 and later.

    • MovesUp

      NSLineMovesUp

      Lines move from bottom to top.

      Available in OS X v10.0 and later.

    • DoesntMove

      NSLineDoesntMove

      Line has no movement.

      Available in OS X v10.0 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.