일부 텍스트를 표시하기 위해 UITextView
을 사용하고 있습니다. 텍스트를 배치 할 때 enumerateLineFragmentsForGlyphRange:withBlock:
메서드를 사용하여 텍스트 줄을 나열합니다.enumerateLineFragmentsForGlyphRange : withBlock : 단어 조각을 반환합니다.
NSInteger shrunkNumberOfLines = 3;
__block NSMutableString *shortenedText = [NSMutableString new];
__block NSInteger currentLine = 0;
__block BOOL needsTruncation = NO;
[detailsTableViewCell.descriptionTextView.layoutManager enumerateLineFragmentsForGlyphRange:NSMakeRange(0, text.length) usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *textContainer, NSRange glyphRange, BOOL *stop) {
if (currentLine < shrunkNumberOfLines) {
NSRange stringRange = ((glyphRange.length + glyphRange.location) <= text.length) ? glyphRange : NSMakeRange(glyphRange.location, (text.length - glyphRange.location));
NSString *appendString = [text substringWithRange:stringRange];
NSLog(@"%@", appendString);
[shortenedText appendString:appendString];
currentLine += 1;
} else {
needsTruncation = YES;
*stop = YES;
}
}];
그러나, 나는 이상한 버그 실행 해요 : 자주는 텍스트 뷰에 표시됩니다 텍스트는 내가 그 appendString
에서 볼 수있는 텍스트와 일치하지 않습니다.
예를 들어, 텍스트 필드의 텍스트는 말할 수 같은 :
President Obama offered a blu
eprint for deeper American en
gagement in the Middle East.
나는했습니다 :
President Obama offered a
blueprint for deeper American
engagement in the Middle East.
이 ...하지만 내 NSLog 문을보고, 그 appendStrings이 같은입니다 hyphenationFactor
을 가지고 놀고, textContainerInsets
이 정확한지 확인하면서 많은 것들을 시도했지만,이 사실을 알 수는 없습니다. enumerateLineFragmentsForGlyphRange:withBlock:
메서드에서 잘못된 줄 바꿈이 발생하는 이유는 무엇입니까?