7

I have a subclassed UITableViewCell that contains a UITextView. I've added NSParagraphStyle as an attribute to the string in a subclassed NSTextStorage. In the following code, I've increased the space between each row in the UITextView.

swift

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

The cursor height elongates till the height of the next line as shown below. This only happens on the rows before the last row.

enter image description here

I've looked at several posts on SO regarding this issue, including this post; however, none of the proposed solutions seem to be working for me.

I've read through the TextKit documentation but haven't found any solution for this issue.

Is there a way to reduce the cursor height?

Community
  • 1
  • 1
akamas
  • 91
  • 5

2 Answers2

1

This works as designed and it's the same on the Mac. It's meant to provide the user with visual feedback of both which line they're on and the height of that line. You should think hard before changing this just because you don't like the way it looks.

That said, the method in the SO post you linked above is the general approach for adjusting the cursor (though the adjusted rect's origin may need to be adjusted as well). What about it didn't work for you? It'd be better to start from there.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • I would argue that it does not work as designed. If the point of the cursor is to show height of the line but you are adjusting the line SPACING then it is incorrectly showing line's height. You can see this if you adjust minimumLineHeight to something large the cursor starts at the bottom of the text and goes up to the top of the line, which makes sense. But if you increase the line spacing the cursor shouldn't go below the text into the spacing as that's not part of the line. – jeffjv Dec 07 '18 at 21:51
  • @jeffjv Then take the time to submit this argument as a bug report to Apple. I didn't design it. – Joshua Nozzi Dec 12 '18 at 14:42
0

an answer related to this issue is given on this thread. just pasting here for future reference. iOS - UITextView lineSpacing make cursor height not same

"you could change cursor height 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; } "
Community
  • 1
  • 1
Moaz Saeed
  • 1,006
  • 3
  • 10
  • 23