I have a UITextView in it's own class, and I'm trying to get the maximum number of lines to work so that the text doesn't go beyond the bounds of the UITextView, along with character wrapping to work, as it wants to always be in word wrapping mode. The line height (4.9) is working however.
I'm not sure as to what is causing this to malfunction. I'd appreciate any help offered.
Here is the code I'm using:
CustomTextView.h
#import <UIKit/UIKit.h>
@interface CustomTextView : UITextView <NSLayoutManagerDelegate>
@end
CustomTextView.m
#import "CustomTextView.h"
@implementation CustomTextView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
self.font = [UIFont systemFontOfSize:21.0];
self.dataDetectorTypes = UIDataDetectorTypeAll;
self.layoutManager.delegate = self;
self.tintColor = [UIColor companyBlue];
[self setLinkTextAttributes:@{NSForegroundColorAttributeName:[UIColor companyBlue]}];
self.contentInset = UIEdgeInsetsMake(0.5, 0, 0, 0);
self.scrollEnabled = NO;
self.textContainer.maximumNumberOfLines = 9;
self.textContainer.lineBreakMode = NSLineBreakByCharWrapping;
}
return self;
}
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
{
return 4.9;
}
@end