Skip to content

NSParagraphStyle ​

NSParagraphStyle represents a set of paragraph styles: alignment, line spacing, paragraph spacing, indentation, and line breaking. It is put into an attributed string as the paragraphStyle attribute and applies to every whole paragraph it covers. A paragraph is the text between two newline characters.

All properties of NSParagraphStyle are read-only. To set values, create an NSMutableParagraphStyle, or call mutableCopy().

When a paragraph style is put into an attributed string, a copy taken at that moment is stored. Changing that NSMutableParagraphStyle afterward doesn't change attributed strings that have already been created. A paragraph style read back from an attributed string is also a copy.

NSParagraphStyle fires no events. Its values never change, so there are no change notifications.

Inheritance: EventTarget → NSObject → NSParagraphStyle

For how to adjust line spacing and alignment, see the guide Displaying styled text.

Constructor ​

NSParagraphStyle()

Creates a default style, equal to the value of NSParagraphStyle.defaultParagraphStyle.

Static properties ​

NSParagraphStyle.defaultParagraphStyle read-only

The system's default paragraph style.

Instance properties ​

Also inherits the properties of NSObject. All are read-only; assigning to them throws TypeError.

PropertyDescription
alignment read-onlyAlignment
lineSpacing read-onlyExtra distance added between lines
paragraphSpacing read-onlySpace left after the end of the paragraph
paragraphSpacingBefore read-onlySpace left before the start of the paragraph
firstLineHeadIndent read-onlyHow far the first line is indented from the left
headIndent read-onlyHow far the lines other than the first are indented from the left
tailIndent read-onlyThe right edge of the lines
lineBreakMode read-onlyWhat happens when a line doesn't fit
minimumLineHeight read-onlyThe minimum line height
maximumLineHeight read-onlyThe maximum line height
lineHeightMultiple read-onlyThe line height as a multiple of the font's natural line height
baseWritingDirection read-onlyThe side the paragraph starts from
hyphenationFactor read-onlyHow aggressively words are hyphenated
defaultTabInterval read-onlyThe default interval between tab stops
allowsDefaultTighteningForTruncation read-onlyWhether letter spacing is tightened before truncating

Instance methods ​

MethodDescription
copy()An immutable copy with the same values
mutableCopy()A mutable copy with the same values

Examples ​

js
const style = NSParagraphStyle.defaultParagraphStyle;
console.log(style.alignment, style.lineSpacing, style.lineBreakMode);

Result: the console prints natural 0 byWordWrapping.

Corresponding iOS API ​

ObjCJS
NSParagraphStyle.defaultParagraphStyleNSParagraphStyle.defaultParagraphStyle
style.alignment = NSTextAlignmentCenterstyle.alignment = 'center' (on NSMutableParagraphStyle)
[style mutableCopy]style.mutableCopy()

See also ​