NSTextBlock
An object that defines the size, spacing, and appearance of a block of text in an attributed string.
Declaration
class NSTextBlockMentioned in
Overview
A text block lets you control how a paragraph looks and where it sits — you can configure its content dimensions, margin, border, padding, and colors.
You create a text block, configure its properties, then assign it to a paragraph by setting the textBlocks property on an NSMutableParagraphStyle and applying that style to a range in an NSMutableAttributedString. To represent a cell inside a table, use NSTextTableBlock instead.
Understand content dimensions
Each text block has three layers around its content: padding, border, and margin. You can configure the width of each layer per edge using setWidth(_:type:for:rectEdge:), or set all edges at once using setWidth(_:type:for:). Use NSTextBlock.Dimension to set the content area’s width, height, and minimum or maximum constraints. Use NSTextBlock.ValueType to specify whether a dimension is an absolute point value or a percentage.
Configure visual appearance
Set a background color using backgroundColor. Configure border colors per edge using setBorderColor(_:for:), or apply a single color to all four edges at once using setBorderColor(_:).
Topics
Initializing a text block
Setting content dimensions
setValue(_:type:for:)value(for:)valueType(for:)setContentWidth(_:type:)contentWidthcontentWidthValueType
Setting layer widths
setWidth(_:type:for:)setWidth(_:type:for:rectEdge:)width(for:rectEdge:)widthValueType(for:rectEdge:)