<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextLineFragment",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextLineFragment"
  },
  "title" : "NSTextLineFragment"
}
-->

# NSTextLineFragment

A class that represents a line fragment as a single textual layout and rendering unit inside a text layout fragment.

```
class NSTextLineFragment
```

## Topics

### Creating line fragments

[`-  initWithAttributedString:range:`](/documentation/AppKit/NSTextLineFragment/init(attributedString:range:))

Creates a new line fragment from the attributed string for the range of characters you specify.

[`-  initWithCoder:`](/documentation/AppKit/NSTextLineFragment/init(coder:))

Creates a new line fragment with from data in an unarchiver.

[`-  initWithString:attributes:range:`](/documentation/AppKit/NSTextLineFragment/init(string:attributes:range:))

Creates a new line fragment using the string, attributes, and range you provide.

### Line fragment characteristics

[`attributedString`](/documentation/AppKit/NSTextLineFragment/attributedString)

The source attributed string.

[`characterRange`](/documentation/AppKit/NSTextLineFragment/characterRange)

The string range for the source attributed string that corresponds to this line fragment.

[`glyphOrigin`](/documentation/AppKit/NSTextLineFragment/glyphOrigin)

Rendering origin for the left-most glyph in the line fragment coordinate system.

[`typographicBounds`](/documentation/AppKit/NSTextLineFragment/typographicBounds)

The typographic bounds that specifies the dimensions of the line fragment for laying out line fragments to each other.

### Finding specific text

[`-  characterIndexForPoint:`](/documentation/AppKit/NSTextLineFragment/characterIndex(for:))

Returns character index for a point inside the line fragment coordinate system.

[`-  fractionOfDistanceThroughGlyphForPoint:`](/documentation/AppKit/NSTextLineFragment/fractionOfDistanceThroughGlyph(for:))

Returns character index for a point inside the line fragment coordinate system.

[`-  locationForCharacterAtIndex:`](/documentation/AppKit/NSTextLineFragment/locationForCharacter(at:))

Returns the location of the character at the specified index.

### Drawing

[`-  drawAtPoint:inContext:`](/documentation/AppKit/NSTextLineFragment/draw(at:in:))

Renders the line fragment contents at the rendering origin.

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)