Class: NSAttributedString
Overview
An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string. The cluster’s two public classes, NSAttributedString and NSMutableAttributedString, declare the programmatic interface for read-only attributed strings and modifiable attributed strings, respectively.
Direct Known Subclasses
Instance Method Summary (collapse)
-
- attribute:atIndex:effectiveRange:
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
-
- attribute:atIndex:longestEffectiveRange:inRange:
Returns the value for the attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
-
- attributedSubstringFromRange:
Returns an NSAttributedString object consisting of the characters and attributes within a given range in the receiver.
-
- attributesAtIndex:effectiveRange:
Returns the attributes for the character at a given index.
-
- attributesAtIndex:longestEffectiveRange:inRange:
Returns the attributes for the character at a given index, and by reference the range over which the attributes apply.
-
- enumerateAttribute:inRange:options:usingBlock:
Executes the Block for the specified attribute run in the specified range.
-
- enumerateAttributesInRange:options:usingBlock:
Executes the Block for each attribute in the range.
-
- initWithAttributedString:
Returns an NSAttributedString object initialized with the characters and attributes of another given attributed string.
-
- initWithString:
Returns an NSAttributedString object initialized with the characters of a given string and no attribute information.
-
- initWithString:attributes:
Returns an NSAttributedString object initialized with a given string and attributes.
-
- isEqualToAttributedString:
Returns a Boolean value that indicates whether the receiver is equal to another given attributed string.
-
- length
Returns the length of the receiver’s string object.
-
- string
Returns the character contents of the receiver as an NSString object.
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) attribute(attributeName, atIndex:index, effectiveRange:aRange)
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies. Raises an NSRangeException if index lies beyond the end of the receiver’s characters.For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.
- (Object) attribute(attributeName, atIndex:index, longestEffectiveRange:aRange, inRange:rangeLimit)
Returns the value for the attribute with a given name of the character at a given index, and by reference the range over which the attribute applies. Raises an NSRangeException if index or any part of rangeLimit lies beyond the end of the receiver’s characters.If you don’t need the longest effective range, it’s far more efficient to use the attribute:atIndex:effectiveRange: method to retrieve the attribute value.For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.
- (NSAttributedString) attributedSubstringFromRange(aRange)
Returns an NSAttributedString object consisting of the characters and attributes within a given range in the receiver. Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters. This method treats the length of the string as a valid range value that returns an empty string.
- (Hash) attributesAtIndex(index, effectiveRange:aRange)
Returns the attributes for the character at a given index. Raises an NSRangeException if index lies beyond the end of the receiver’s characters.For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.
- (Hash) attributesAtIndex(index, longestEffectiveRange:aRange, inRange:rangeLimit)
Returns the attributes for the character at a given index, and by reference the range over which the attributes apply. Raises an NSRangeException if index or any part of rangeLimit lies beyond the end of the receiver’s characters.If you don’t need the range information, it’s far more efficient to use the attributesAtIndex:effectiveRange: method to retrieve the attribute value.For information about where to find the attribute keys for the returned dictionary, see the overview section of this document.
- (Object) enumerateAttribute(attrName, inRange:enumerationRange, options:opts, usingBlock:block)
Executes the Block for the specified attribute run in the specified range. If this method is sent to an instance of NSMutableAttributedString, mutation (deletion, addition, or change) is allowed, as long as it is within the range provided to the block; after a mutation, the enumeration continues with the range immediately following the processed range, after the length of the processed range is adjusted for the mutation. (The enumerator basically assumes any change in length occurs in the specified range.) For example, if block is called with a range starting at location N, and the block deletes all the characters in the supplied range, the next call will also pass N as the index of the range.
- (Object) enumerateAttributesInRange(enumerationRange, options:opts, usingBlock:block)
Executes the Block for each attribute in the range. If this method is sent to an instance of NSMutableAttributedString, mutation (deletion, addition, or change) is allowed, as long as it is within the range provided to the block; after a mutation, the enumeration continues with the range immediately following the processed range, after the length of the processed range is adjusted for the mutation. (The enumerator basically assumes any change in length occurs in the specified range.) For example, if block is called with a range starting at location N, and the block deletes all the characters in the supplied range, the next call will also pass N as the index of the range.
- (Object) initWithAttributedString(attributedString)
Returns an NSAttributedString object initialized with the characters and attributes of another given attributed string.
- (Object) initWithString(aString)
Returns an NSAttributedString object initialized with the characters of a given string and no attribute information.
- (Object) initWithString(aString, attributes:attributes)
Returns an NSAttributedString object initialized with a given string and attributes. Returns an NSAttributedString object initialized with the characters of aString and the attributes of attributes. The returned object might be different from the original receiver.
- (Boolean) isEqualToAttributedString(otherString)
Returns a Boolean value that indicates whether the receiver is equal to another given attributed string. Attributed strings must match in both characters and attributes to be equal.
- (Integer) length
Returns the length of the receiver’s string object.
- (String) string
Returns the character contents of the receiver as an NSString object. This method doesn’t strip out attachment characters.For performance reasons, this method returns the current backing store of the attributed string object. If you want to maintain a snapshot of this as you manipulate the returned string, you should make a copy of the appropriate substring.This primitive method must guarantee efficient access to an attributed string’s characters; subclasses should implement it to execute in O(1) time.