Last Updated: July 10, 2018
· novalagung

iOS - Change Line Height of UITextView

We can change line height of UITextView using NSMutableParagraphStyle by changing value of lineSpacing attribute.

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineSpacing = 17;
textView.attributedText = [[NSAttributedString alloc] 
    initWithString:@"Predefined Text" 
    attributes:@{NSParagraphStyleAttributeName : style}];
textView.text = @"Your text"

Example result :


if your UITextView's editable is enabled, you will see the caret is overflowing to top. you need to subclass UITextView and override caretRectForPosition: method to change height of the caret.

- (CGRect)caretRectForPosition:(UITextPosition *)position {
    CGRect originalRect = [super caretRectForPosition:position];
    originalRect.size.height = 18.;
    return originalRect;

useful link, see here :

Say Thanks

1 Response
Add your response


thnkyou for this i was looking for this for a long time now
I'm already pretty sure that it can't be done with any public API, but I still want to ask:

Is there any way to change the line height in a UITextView?

Would be enough to do it statically, no need to change it at runtime. The problem is that the default line height is just WAY too small. Text will look extremely compressed and is a nightmare when trying to write longer texts.
best regards

about 1 month ago ·