Greetings,
you can override the override func draw(at point: CGPoint, in context: CGContext) from NSTextLayoutFragment and iterate over the text line fragments to customize it:
override func draw(at point: CGPoint, in context: CGContext) {
for lineFragment in textLineFragments {
lineFragment.draw(at: lineFragment.typographicBounds.origin, in: context)
}
}
Source / Example: krzyzanowskim/STTextView