Class

NSTextBlock

A block of text laid out in a subregion of the text container.

Overview

A text block appears as an attribute of a paragraph, and as part of the paragraph style. The most important subclass of NSTextBlock 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.

Topics

Creating text blocks

init()

Initializes and returns an empty text block object.

Working with dimensions of content

func value(for: NSTextBlock.Dimension)

Returns the value of the specified text block dimension.

func valueType(for: NSTextBlock.Dimension)

Returns the value type of the specified text block dimension.

var contentWidth: CGFloat

The width of the text block.

var contentWidthValueType: NSTextBlock.ValueType

The type of value stored for the text block width.

Getting and setting margins, borders, and padding

func setWidth(CGFloat, type: NSTextBlock.ValueType, for: NSTextBlock.Layer, edge: NSRectEdge)

Sets the width of a specified edge of a specified layer of the text block.

func setWidth(CGFloat, type: NSTextBlock.ValueType, for: NSTextBlock.Layer)

Sets the width of all edges of a specified layer of the text block.

func width(for: NSTextBlock.Layer, edge: NSRectEdge)

Returns the width of an edge of a specified layer of the text block.

func widthValueType(for: NSTextBlock.Layer, edge: NSRectEdge)

Returns the value type of an edge of a specified layer of the text block.

Getting and setting alignment

var verticalAlignment: NSTextBlock.VerticalAlignment

The vertical alignment of the text block.

Working with color

var backgroundColor: NSColor?

The background color of the text block.

func setBorderColor(NSColor?, for: NSRectEdge)

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

func setBorderColor(NSColor?)

Sets the color of all borders of the text block.

func borderColor(for: NSRectEdge)

Returns the border color of the specified text block edge.

Determining size and position of a text block

func rectForLayout(at: NSPoint, in: NSRect, textContainer: NSTextContainer, characterRange: NSRange)

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

func boundsRect(forContentRect: NSRect, in: NSRect, textContainer: NSTextContainer, characterRange: NSRange)

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

Drawing colors and decorations

func drawBackground(withFrame: NSRect, in: NSView, characterRange: NSRange, layoutManager: NSLayoutManager)

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

Constants

enum NSTextBlock.ValueType

The following constants specify values used by the methods setValue(_:type:for:) and valueType(for:) to specify text block value types.

enum NSTextBlock.Dimension

The following constants specify values used by the methods setValue(_:type:for:), value(for:), and valueType(for:) to specify text block dimensions.

enum NSTextBlock.Layer

The following constants specify values used by the properties and methods contentWidthValueType, setWidth(_:type:for:edge:), setWidth(_:type:for:), width(for:edge:), and widthValueType(for:edge:) to specify text block layer values.

enum NSTextBlock.VerticalAlignment

The following constants specify values used by the property verticalAlignment to specify vertical alignment.

Instance Methods

Relationships

Inherits From

See Also

Layout

class NSLayoutManager

An object that coordinates the layout and display of characters held in an NSTextStorage object.

protocol NSLayoutManagerDelegate

A set of optional methods implemented by delegates of NSLayoutManager objects.

class NSTextContainer

A region where text is laid out.

class NSATSTypesetter

A concrete subclass of NSTypesetter that places glyphs during the text layout process.

class NSTypesetter

An abstract class that performs various type layout tasks.

protocol NSTextLayoutOrientationProvider

A set of methods that define the orientation of text for an object.