Mac Developer Library

Developer

AppKit Framework Reference NSTextBlock Class Reference

Options
Deployment Target:

On This Page
Language:

NSTextBlock

Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.4 and later.

NSTextBlock objects represent a block of text laid out in a subregion of the text container. Text blocks appear as attributes on paragraphs, as part of the paragraph style.

The most important subclass is NSTextTableBlock, which represents a block of text that appears as a cell in a table. The table itself is represented by a separate class, NSTextTable, which is referenced by all of its NSTextTableBlock objects and which controls their sizing and positioning.

  • Initializes and returns an empty text block object.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    An initialized text block object.

    Discussion

    This is the designated initializer for NSTextBlock.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the vertical alignment of the text block.

    Declaration

    Swift

    var verticalAlignment: NSTextBlockVerticalAlignment

    Objective-C

    @property NSTextBlockVerticalAlignment verticalAlignment

    Parameters

    alignment

    The new vertical alignment for the text block.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the vertical alignment of the text block.

    Declaration

    Swift

    var verticalAlignment: NSTextBlockVerticalAlignment

    Objective-C

    @property NSTextBlockVerticalAlignment verticalAlignment

    Return Value

    The vertical alignment of the text block.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the background color of the text block.

    Declaration

    Swift

    @NSCopying var backgroundColor: NSColor?

    Objective-C

    @property(copy) NSColor *backgroundColor

    Parameters

    color

    The new background color.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the background color of the text block.

    Declaration

    Swift

    @NSCopying var backgroundColor: NSColor?

    Objective-C

    @property(copy) NSColor *backgroundColor

    Return Value

    The background color of the text block.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the border color of the specified edge of the text block.

    Declaration

    Swift

    func setBorderColor(_ color: NSColor?, forEdge edge: NSRectEdge)

    Objective-C

    - (void)setBorderColor:(NSColor *)color forEdge:(NSRectEdge)edge

    Parameters

    color

    The new color.

    edge

    The edge whose color is to be set.

    Discussion

    This setting has no visible effect unless the border width is larger than the default, which is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the color of all borders of the text block.

    Declaration

    Swift

    func setBorderColor(_ color: NSColor?)

    Objective-C

    - (void)setBorderColor:(NSColor *)color

    Parameters

    color

    The new color.

    Discussion

    This setting has no visible effect unless the border width is larger than the default, which is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the border color of the specified text block edge.

    Declaration

    Swift

    func borderColorForEdge(_ edge: NSRectEdge) -> NSColor?

    Objective-C

    - (NSColor *)borderColorForEdge:(NSRectEdge)edge

    Parameters

    edge

    The edge of the text block in question.

    Return Value

    The border color of the text block edge edge.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the rectangle within which glyphs should be laid out for the specified arguments.

    Declaration

    Swift

    func rectForLayoutAtPoint(_ startingPoint: NSPoint, inRect rect: NSRect, textContainer textContainer: NSTextContainer, characterRange charRange: NSRange) -> NSRect

    Objective-C

    - (NSRect)rectForLayoutAtPoint:(NSPoint)startingPoint inRect:(NSRect)rect textContainer:(NSTextContainer *)textContainer characterRange:(NSRange)charRange

    Parameters

    startingPoint

    The location, in container coordinates, where layout begins.

    rect

    The rectangle in which the block is constrained to lie. For top-level blocks, this is the container rectangle of textContainer; for nested blocks, this is the layout rectangle of the enclosing block.

    textContainer

    The text container being used for the layout.

    charRange

    The range of the characters in the NSTextStorage object whose glyphs are to be drawn.

    Return Value

    The rectangle within which glyphs should be laid out.

    Discussion

    This method is called by the typesetter before the text block is laid out to return the rectangle within which glyphs should be laid out.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the rectangle the text in the block actually occupies, including padding, borders, and margins.

    Declaration

    Swift

    func boundsRectForContentRect(_ contentRect: NSRect, inRect rect: NSRect, textContainer textContainer: NSTextContainer, characterRange charRange: NSRange) -> NSRect

    Objective-C

    - (NSRect)boundsRectForContentRect:(NSRect)contentRect inRect:(NSRect)rect textContainer:(NSTextContainer *)textContainer characterRange:(NSRange)charRange

    Parameters

    contentRect

    The actual rectangle in which the text was laid out, as determined by rectForLayoutAtPoint:inRect:textContainer:characterRange:.

    rect

    The initial rectangle in textContainer proposed by the typesetter.

    textContainer

    The text container being used for the layout.

    charRange

    The range of the characters in the NSTextStorage object whose glyphs are to be drawn.

    Return Value

    The rectangle the text in the block actually occupies, including padding, borders, and margins.

    Discussion

    This methods is called by the typesetter after the text block is laid out to return the rectangle the text in the block actually occupies, including padding, borders, and margins.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Called by the layout manager to draw any colors and other decorations before the text is drawn.

    Declaration

    Swift

    func drawBackgroundWithFrame(_ frameRect: NSRect, inView controlView: NSView, characterRange charRange: NSRange, layoutManager layoutManager: NSLayoutManager)

    Objective-C

    - (void)drawBackgroundWithFrame:(NSRect)frameRect inView:(NSView *)controlView characterRange:(NSRange)charRange layoutManager:(NSLayoutManager *)layoutManager

    Parameters

    frameRect

    The bounds rectangle in view coordinates.

    controlView

    The view in which drawing occurs.

    charRange

    The range of the characters in the NSTextStorage object whose glyphs are to be drawn.

    layoutManager

    The layout manager controlling the typesetting.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The following constants specify values used by the methods setValue:type:forDimension: and valueTypeForDimension:

    Declaration

    Swift

    enum NSTextBlockValueType : UInt { case AbsoluteValueType case PercentageValueType }

    Objective-C

    enum { NSTextBlockAbsoluteValueType = 0, NSTextBlockPercentageValueType = 1 }; typedef NSUInteger NSTextBlockValueType;

    Constants

    • AbsoluteValueType

      NSTextBlockAbsoluteValueType

      Absolute value in points.

      Available in OS X v10.4 and later.

    • PercentageValueType

      NSTextBlockPercentageValueType

      Percentage value (out of 100).

      Available in OS X v10.4 and later.

    • NSTextBlockValueType

      NSTextBlockValueType

      A type defined for the text block value type constants.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The following constants specify values used by the methods setValue:type:forDimension:, valueForDimension:, and valueTypeForDimension:.

    Declaration

    Swift

    enum NSTextBlockDimension : UInt { case Width case MinimumWidth case MaximumWidth case Height case MinimumHeight case MaximumHeight }

    Objective-C

    enum { NSTextBlockWidth = 0, NSTextBlockMinimumWidth = 1, NSTextBlockMaximumWidth = 2, NSTextBlockHeight = 4, NSTextBlockMinimumHeight = 5, NSTextBlockMaximumHeight = 6 }; typedef NSUInteger NSTextBlockDimension;

    Constants

    • Width

      NSTextBlockWidth

      Width of the text block.

      Available in OS X v10.4 and later.

    • MinimumWidth

      NSTextBlockMinimumWidth

      Minimum width of the text block.

      Available in OS X v10.4 and later.

    • MaximumWidth

      NSTextBlockMaximumWidth

      Maximum width of the text block.

      Available in OS X v10.4 and later.

    • Height

      NSTextBlockHeight

      Height of the text block.

      Available in OS X v10.4 and later.

    • MinimumHeight

      NSTextBlockMinimumHeight

      Minimum height of the text block.

      Available in OS X v10.4 and later.

    • MaximumHeight

      NSTextBlockMaximumHeight

      Maximum height of the text block.

      Available in OS X v10.4 and later.

    • NSTextBlockDimension

      NSTextBlockDimension

      A type defined for the text block dimension constants.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Declaration

    Swift

    enum NSTextBlockLayer : Int { case Padding case Border case Margin }

    Objective-C

    enum { NSTextBlockPadding = -1, NSTextBlockBorder = 0, NSTextBlockMargin = 1 }; typedef NSInteger NSTextBlockLayer;

    Constants

    • Padding

      NSTextBlockPadding

      Padding of the text block: space surrounding the content area extending to the border.

      Available in OS X v10.4 and later.

    • Border

      NSTextBlockBorder

      Border of the text block: space between padding and margin, typically colored to present a visible boundary.

      Available in OS X v10.4 and later.

    • Margin

      NSTextBlockMargin

      Margin of the text block: space surrounding the border.

      Available in OS X v10.4 and later.

    • NSTextBlockLayer

      NSTextBlockLayer

      A type defined for the text block layer constants.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The following constants specify values used by the methods setVerticalAlignment: and verticalAlignment.

    Declaration

    Swift

    enum NSTextBlockVerticalAlignment : UInt { case TopAlignment case MiddleAlignment case BottomAlignment case BaselineAlignment }

    Objective-C

    enum { NSTextBlockTopAlignment = 0, NSTextBlockMiddleAlignment = 1, NSTextBlockBottomAlignment = 2, NSTextBlockBaselineAlignment = 3 }; typedef NSUInteger NSTextBlockVerticalAlignment;

    Constants

    • TopAlignment

      NSTextBlockTopAlignment

      Aligns adjacent blocks at their top.

      Available in OS X v10.4 and later.

    • MiddleAlignment

      NSTextBlockMiddleAlignment

      Aligns adjacent blocks at their middle.

      Available in OS X v10.4 and later.

    • BottomAlignment

      NSTextBlockBottomAlignment

      Aligns adjacent blocks at their bottom.

      Available in OS X v10.4 and later.

    • BaselineAlignment

      NSTextBlockBaselineAlignment

      Aligns adjacent blocks at the baseline of the first line of text in the block.

      Available in OS X v10.4 and later.

    • NSTextBlockVerticalAlignment

      NSTextBlockVerticalAlignment

      A type defined for the text block vertical alignment constants.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.