Declare that you implement the protocol by adding
<NSLayoutManagerDelegate>
to your interface. Then install:
yourTextView.layoutManager.delegate = self;
Then override this delegate method:
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
{
return 5;
}
UPDATE: I recently discovered that this can also be done using the API NSMutableParagraphStyle setLineSpacing:.
In order to provide the always useful copy-paste function of the snippet code, here you go!
NSMutableParagraphStyle *myStyle = [[NSMutableParagraphStyle alloc] init];
[myStyle setLineSpacing:myLineSpacingInt];
[myString addAttribute:myDesiredAttribute value:myStyle range:myDesiredRange];
[myViewElement setAttributedText:myString];
^ myViewElementmaybe UITextField, UILabelor UITextView.
source
share