Reputation: 1752
I am trying to find a way to draw the checkbox in TextKit 2, Trying to use NSTextLayoutFragment and NSLayoutManager Delegate methods to draw the checkbox and also paragraph alongside the checkbox.
Custom Fragment :
class CheckListFragment : NSTextLayoutFragment{
override func draw(at point: CGPoint, in context: CGContext) {
}
}
Delegate Method :
func textLayoutManager(_ textLayoutManager: NSTextLayoutManager, textLayoutFragmentFor location: any NSTextLocation, in textElement: NSTextElement) -> NSTextLayoutFragment {
return CheckListFragment(textElement: textElement, range: textElement.elementRange)
}
I want the Text to be indented(☑️ some Text), the cursor should start from where the text is starting but not from the checkbox itself(☑️ │some Text), so when i empty the text with backspace the insertion point has to only go till the starting point of the text.
I am trying to use custom fragment to achieve this, with this approach I am not getting any control, Suggest me if there is any better way of doing this ?
Upvotes: 2
Views: 39