AttributedString
A container holding both characters and associated attributes.
Examples
Enumerate attribute ranges:
var effectiveRange = {};
var textLength = attributedString.length;
var index = 0;
while (index < textLength) {
console.log(attributedString.getAttributesAtIndex(index, effectiveRange));
index += effectiveRange.length;
}
Creating
-
::constructor(text) -
Create a new AttributedString with the given text.
Argument Description textText content for the AttributedString. -
::clone() -
Return a clone of this AttributedString. The attributes are shallow copied.
Characters
-
::string -
Read-only string
-
::deleteRange(location, length) -
Delete characters and attributes in range.
Argument Description locationRange start character index. lengthRange length. -
::insertText(location, text) -
Insert text into the string.
Argument Description locationLocation to insert at. texttext to insert. -
::appendText(text) -
Append text to the end of the string.
Argument Description texttext to insert. -
::replaceRange(location, length, text) -
Replace existing text range with new text.
Argument Description locationReplace range start character index. lengthReplace range length. texttext to insert.
Attributes
-
::getAttributesAtIndex(index, effectiveRange?, longestEffectiveRange?) -
Argument Description indexThe character index. effectiveRange?Objectwhoselocationandlengthproperties are set to effective range of the attributes.longestEffectiveRange?Objectwhoselocationandlengthproperties are set to longest effective range of the attributes.Return Values Returns an Objectwith keys for each attribute at the given character index, and by reference the range over which the attributes apply. -
::getAttributeAtIndex(attribute, index, effectiveRange?, longestEffectiveRange?) -
Argument Description attributeAttribute Stringname.indexThe character index. effectiveRange?Objectwhoselocationandlengthproperties are set to effective range of the attribute.longestEffectiveRange?Objectwhoselocationandlengthproperties are set to longest effective range of the attribute.Return Values Returns the value for an attribute with a given name of the character at a given character index, and by reference the range over which the attribute applies. -
::addAttributeInRange(attribute, value, index, length) -
Adds an attribute to the characters in the given range.
Argument Description attributeThe Stringattribute name.valueThe attribute value. indexStart character index. lengthRange length. -
::addAttributesInRange(attributes, index, length) -
Adds attributes to the characters in the given range.
Argument Description attributesObjectwith keys and values for each attributeindexStart index. lengthRange length. -
::removeAttributeInRange(attribute, index, length) -
Removes the attribute from the given range.
Argument Description attributeThe Stringattribute nameindexStart character index. lengthRange length.
Extracting a Substring
-
::attributedSubstringFromRange(location?, length?) -
Argument Description location?Range start character index. Defaults to 0. length?Range length. Defaults to end of string. Return Values Returns an AttributedStringobject consisting of the characters and attributes within a given range in the receiver.
Debug
-
::toString() -
Return Values Returns debug string for this item.