CFAttributedString

Overview

Instances of CFAttributedString manage character strings and associated sets of attributes (for example, font and kerning information) that apply to individual characters or ranges of characters in the string. CFAttributedString as defined in Core Foundation provides the basic container functionality, while higher levels provide definitions for standard attributes, their values, and additional behaviors involving these. CFAttributedString represents an immutable string—use CFMutableAttributedStringRef to create and manage an attributed string that can be changed after it has been created.

CFAttributedString is not a “subclass” of CFString; that is, it does not respond to CFString function calls. CFAttributedString conceptually contains a CFString to which it applies attributes. This protects you from ambiguities caused by the semantic differences between simple and attributed string.

Attributes are identified by key/value pairs stored in CFDictionary objects. Keys must be CFString objects, while the corresponding values are CFType objects of an appropriate type. See the attribute constants in NSAttributedString Application Kit Additions Reference or NSAttributedString UIKit Additions Reference for standard attribute names.

CFAttributedString is “toll-free bridged” with its Foundation counterpart, NSAttributedString. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSAttributedString * parameter, you can pass in a CFAttributedStringRef, and in a function where you see a CFAttributedStringRef parameter, you can pass in an NSAttributedString instance. This also applies to concrete subclasses of NSAttributedString. See Toll-Free Bridged Types for more information on toll-free bridging.

Topics

Creating a CFAttributedString

CFAttributedStringCreate

Creates an attributed string with specified string and attributes.

CFAttributedStringCreateCopy

Creates an immutable copy of an attributed string.

CFAttributedStringCreateWithSubstring

Creates a sub-attributed string from the specified range.

CFAttributedStringGetLength

Returns the length of the attributed string in characters.

CFAttributedStringGetString

Returns the string for an attributed string.

Accessing Attributes

CFAttributedStringGetAttribute

Returns the value of a given attribute of an attributed string at a specified location.

CFAttributedStringGetAttributes

Returns the attributes of an attributed string at a specified location.

CFAttributedStringGetAttributeAndLongestEffectiveRange

Returns the value of a given attribute of an attributed string at a specified location.

CFAttributedStringGetAttributesAndLongestEffectiveRange

Returns the attributes of an attributed string at a specified location.

Getting Attributed String Properties

CFAttributedStringGetTypeID

Returns the type identifier for the CFAttributedString opaque type.

Data Types

CFAttributedStringRef

A reference to a CFAttributedString object.

See Also

Opaque Types

CFFileDescriptor

The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.

CFStringTokenizer

CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.