У меня есть прокручиваемый UITextView с его layoutManager maximumNumberOfLines, установленным в 9, который отлично работает, но я не могу найти метод в NSLayoutManager, который ограничивает текст не выходящим за рамки UITextView.
Возьмем, к примеру, на этом скриншоте, курсор находится на 9-й строке (первая строка обрезана в верхней части экрана, поэтому не обращайте на это внимания). Если пользователь продолжает вводить новые символы, пробелы или нажать клавишу возврата, курсор продолжает выходить из экрана, а строка UITextView продолжает увеличиваться.
Я не хочу ограничивать количество символов UITextView из-за того, что инородные символы имеют разные размеры.
Я пытался исправить это несколько недель; Я бы очень признателен за любую помощь.
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.scrollEnabled = NO;
self.textContainerInset = UIEdgeInsetsMake(8.5, 0, 0, 0);
self.textContainer.maximumNumberOfLines = 9;
}
return self;
}
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
{
return 4.9;
}
@end
Обновление, все еще не разрешено