I have a custom, editable UITextView and I modified the paragraph spacing like so:
func layoutManager(_ layoutManager: NSLayoutManager, paragraphSpacingBeforeGlyphAt glyphIndex: Int, withProposedLineFragmentRect rect: CGRect) -> CGFloat {
return 10
}
func layoutManager(_ layoutManager: NSLayoutManager, paragraphSpacingAfterGlyphAt glyphIndex: Int, withProposedLineFragmentRect rect: CGRect) -> CGFloat {
return 10
}
This causes the cursor being very big. I've tried to fix that by overriding the caretRect
:
override func caretRect(for position: UITextPosition) -> CGRect {
let defaulCaretRect = super.caretRect(for: position)
return CGRect(x: defaulCaretRect.origin.x, y: defaulCaretRect.origin.y, width: defaulCaretRect.width, height: 22)
}
It works perfectly in some cases, but in other cases, the origin.y
is wrong:
If I ajdust the origin.y
, it breaks it in cases where it was correct. I don't know how to recognize if the origin.y
needs to be fixed or not. Am I missing something?
I've seen here on SO some older answers using the following:
rect.size.height = font.pointSize - font.descender
But fore some reason, this had no effect. Any ideas?
Lastly, the bigger paragraph spacing is also causing too big selection handles:
Any way of resolving that as well?