Changing the line spacing property of an NSParagraphStyle causes the cursor to lengthen

I have a subclass UITableViewCell containing a UITextView. I added NSParagraphStyle as an attribute for a string in a subclass of NSTextStorage. In the following code, I increased the space between each row in a UITextView.

speed

let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 11 myCustomTextStorage.appendAttributedString(NSAttributedString(string: someText, attributes: [NSParagraphStyleAttributeName: paragraphStyle])) 

The height of the cursor extends to the height of the next line, as shown below. This only happens in lines to the last line.

enter image description here

I looked through several posts on this subject, including this post ; however, none of the proposed solutions seem to work for me.

I read the TextKit documentation but could not find a solution for this problem.

Is there a way to reduce the height of the cursor?

+6
source share
2 answers

This works the same as on a Mac. It is intended to provide the user with visual feedback on which line they are on and at the height of that line. You have to think a lot before changing this, because you donโ€™t like what it looks like.

However, the method in the SO message that you linked above is a general approach to setting the cursor (although the adjusted direct origin may need to be adjusted as well). What didnโ€™t work with you? Better to start from now on.

0
source

This topic gives an answer related to this problem. just pasting here for future reference. iOS - UITextView lineSpacing makes cursor height not the same

"you can change the height of the cursor by subclassing the UITextView, then override the caretRectForPosition: position function. For example:

  • (CGRect) caretRectForPosition: (UITextPosition *) position {CGRect originalRect = [super caretRectForPosition: position]; originalRect.size.height = 18.0; return originalRect; } "
0
source

Source: https://habr.com/ru/post/985383/


All Articles