<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextLineFragment",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "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

[`init(attributedString: NSAttributedString, range: NSRange)`](/documentation/UIKit/NSTextLineFragment/init(attributedString:range:))

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

[`init?(coder: NSCoder)`](/documentation/UIKit/NSTextLineFragment/init(coder:))

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

[`convenience init(string: String, attributes: [NSAttributedString.Key : Any], range: NSRange)`](/documentation/UIKit/NSTextLineFragment/init(string:attributes:range:))

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

### Line fragment characteristics

[`var attributedString: NSAttributedString`](/documentation/UIKit/NSTextLineFragment/attributedString)

The source attributed string.

[`var characterRange: NSRange`](/documentation/UIKit/NSTextLineFragment/characterRange)

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

[`var glyphOrigin: CGPoint`](/documentation/UIKit/NSTextLineFragment/glyphOrigin)

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

[`var typographicBounds: CGRect`](/documentation/UIKit/NSTextLineFragment/typographicBounds)

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

### Finding specific text

[`func characterIndex(for: CGPoint) -> Int`](/documentation/UIKit/NSTextLineFragment/characterIndex(for:))

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

[`func fractionOfDistanceThroughGlyph(for: CGPoint) -> CGFloat`](/documentation/UIKit/NSTextLineFragment/fractionOfDistanceThroughGlyph(for:))

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

[`func locationForCharacter(at: Int) -> CGPoint`](/documentation/UIKit/NSTextLineFragment/locationForCharacter(at:))

Returns the location of the character at the specified index.

### Drawing

[`func draw(at: CGPoint, in: CGContext)`](/documentation/UIKit/NSTextLineFragment/draw(at:in:))

Renders the line fragment contents at the rendering origin.

## Relationships

### Conforms To

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

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

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

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

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

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

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

[`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)