Instance Method

addAttributes(_:range:)

Adds the given collection of attributes to the characters in the specified range.

Declaration

func addAttributes(_ attrs: [NSAttributedStringKey : Any] = [:], range: NSRange)

Parameters

attributes

A dictionary containing the attributes to add. Attribute keys can be supplied by another framework or can be custom ones you define. For information about the system-supplied attribute keys, see the Constants section in NSAttributedString.

aRange

The range of characters to which the specified attributes apply.

Discussion

You may assign any name/value pair you wish to a range of characters. Raises an invalidArgumentException if attributes is nil and an rangeException if any part of aRange lies beyond the end of the receiver’s characters.

See Also

Changing attributes

func setAttributes([NSAttributedStringKey : Any]?, range: NSRange)

Sets the attributes for the characters in the specified range to the specified attributes.

func addAttribute(NSAttributedStringKey, value: Any, range: NSRange)

Adds an attribute with the given name and value to the characters in the specified range.

func removeAttribute(NSAttributedStringKey, range: NSRange)

Removes the named attribute from the characters in the specified range.

func applyFontTraits(NSFontTraitMask, range: NSRange)

Applies the font attributes specified by mask to the characters in aRange.

func setAlignment(NSTextAlignment, range: NSRange)

Sets the alignment characteristic of the paragraph style attribute for the characters in aRange to alignment.

func setBaseWritingDirection(NSWritingDirection, range: NSRange)

Sets the base writing direction for the characters in range to writingDirection.

func subscriptRange(NSRange)

Decrements the value of the superscript attribute for characters in aRange by 1.

func superscriptRange(NSRange)

Increments the value of the superscript attribute for characters in aRange by 1.

func unscriptRange(NSRange)

Removes the superscript attribute from the characters in aRange.