addAttribute(_:value:range:)
Adds an attribute with the given name and value to the characters in the specified range.
Declaration
func addAttribute(_ name: NSAttributedString.Key, value: Any, range: NSRange)Parameters
- name:
A string specifying the attribute name. 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.
- value:
The attribute value associated with
name. - range:
The range of characters to which the specified attribute/value pair applies.
Discussion
You may assign any name/value pair you wish to a range of characters. Raises an invalidArgumentException if name or value is nil and an rangeException if any part of range lies beyond the end of the receiver’s characters.