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 : http://stackoverflow.com/questions/20207961/ios-uitextview-linespacing-make-cursor-height-not-same/20311650#20311650
Written by Noval Agung Prayogo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objective-c
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#