Class: NSMutableAttributedString

Inherits:
NSAttributedString show all

Overview

NSMutableAttributedString declares the programmatic interface to objects that manage mutable attributed strings. You can add and remove characters (raw strings) and attributes separately or together as attributed strings. See the class description for NSAttributedString for more information about attributed strings.

Instance Method Summary (collapse)

Methods inherited from NSAttributedString

#attribute:atIndex:effectiveRange:, #attribute:atIndex:longestEffectiveRange:inRange:, #attributedSubstringFromRange:, #attributesAtIndex:effectiveRange:, #attributesAtIndex:longestEffectiveRange:inRange:, #enumerateAttribute:inRange:options:usingBlock:, #enumerateAttributesInRange:options:usingBlock:, #initWithAttributedString:, #initWithString:, #initWithString:attributes:, #isEqualToAttributedString:, #length, #string

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Method Details

- (Object) addAttribute(name, value:value, range:aRange)

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

You may assign any name/value pair you wish to a range of characters, in addition to the standard attributes described in the “Constants” section of NSAttributedString Additions. Raises an NSInvalidArgumentException if name or value is nil and an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

Parameters:

  • name (String)

    A string specifying the attribute name. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.

  • value (Object)

    The attribute value associated with name.

  • aRange (NSRange)

    The range of characters to which the specified attribute/value pair applies.

Returns:

- (Object) addAttributes(attributes, range:aRange)

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

You may assign any name/value pair you wish to a range of characters, in addition to the standard attributes described in the “Constants” section of NSAttributedString Additions. Raises an NSInvalidArgumentException if attributes is nil and an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

Parameters:

  • attributes (Hash)

    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 where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.

  • aRange (NSRange)

    The range of characters to which the specified attributes apply.

Returns:

- (Object) appendAttributedString(attributedString)

Adds the characters and attributes of a given attributed string to the end of the receiver.

Parameters:

  • attributedString (NSAttributedString)

    The string whose characters and attributes are added.

Returns:

- (Object) beginEditing

Overridden by subclasses to buffer or optimize a series of changes to the receiver’s characters or attributes, until it receives a matching endEditing message, upon which it can consolidate changes and notify any observers that it has changed.

You can nest pairs of beginEditing and endEditing messages.

Returns:

- (Object) deleteCharactersInRange(aRange)

Deletes the characters in the given range along with their associated attributes.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

Parameters:

  • aRange (NSRange)

    A range specifying the characters to delete.

Returns:

- (Object) endEditing

Overridden by subclasses to consolidate changes made since a previous beginEditing message and to notify any observers of the changes.

The NSMutableAttributedString implementation does nothing. NSTextStorage, for example, overrides this method to invoke fixAttributesInRange: and to inform its NSLayoutManager objects that they need to re-lay the text.

Returns:

- (Object) insertAttributedString(attributedString, atIndex:index)

Inserts the characters and attributes of the given attributed string into the receiver at the given index. The new characters and attributes begin at the given index and the existing characters and attributes from the index to the end of the receiver are shifted by the length of the attributed string. Raises an NSRangeException if index lies beyond the end of the receiver’s characters.

Parameters:

  • attributedString (NSAttributedString)

    The string whose characters and attributes are inserted.

  • index (Integer)

    The index at which the characters and attributes are inserted.

Returns:

- (String) mutableString

Returns the character contents of the receiver as an NSMutableString object.

The receiver tracks changes to this string and keeps its attribute mappings up to date.

Returns:

  • (String)

    The mutable string object.

- (Object) removeAttribute(name, range:aRange)

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

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

Parameters:

  • name (String)

    A string specifying the attribute name to remove. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.

  • aRange (NSRange)

    The range of characters from which the specified attribute is removed.

Returns:

- (Object) replaceCharactersInRange(aRange, withAttributedString:attributedString)

Replaces the characters and attributes in a given range with the characters and attributes of the given attributed string.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

Parameters:

  • aRange (NSRange)

    The range of characters and attributes replaced.

  • attributedString (NSAttributedString)

    The attributed string whose characters and attributes replace those in the specified range.

Returns:

- (Object) replaceCharactersInRange(aRange, withString:aString)

Replaces the characters in the given range with the characters of the given string. The new characters inherit the attributes of the first replaced character from aRange. Where the length of aRange is 0, the new characters inherit the attributes of the character preceding aRange if it has any, otherwise of the character following aRange.Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

Parameters:

  • aRange (NSRange)

    A range specifying the characters to replace.

  • aString (String)

    A string specifying the characters to replace those in aRange.

Returns:

- (Object) setAttributedString(attributedString)

Replaces the receiver’s entire contents with the characters and attributes of the given attributed string.

Parameters:

  • attributedString (NSAttributedString)

    The attributed string whose characters and attributes replace those in the receiver.

Returns:

- (Object) setAttributes(attributes, range:aRange)

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

These new attributes replace any attributes previously associated with the characters in aRange. Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.To set attributes for a zero-length NSMutableAttributedString displayed in a text view, use the NSTextView method setTypingAttributes:.

Parameters:

  • attributes (Hash)

    A dictionary containing the attributes to set. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.

  • aRange (NSRange)

    The range of characters whose attributes are set.

Returns: