Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions YYText/YYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,8 @@ - (void)setAttributedText:(NSAttributedString *)attributedText {
if (!_state.insideUndoBlock) {
[self _resetUndoAndRedoStack];
}

[self invalidateIntrinsicContentSize];
}

- (void)setTextVerticalAlignment:(YYTextVerticalAlignment)textVerticalAlignment {
Expand Down Expand Up @@ -3644,6 +3646,25 @@ - (NSArray *)selectionRectsForRange:(YYTextRange *)range {
return rects;
}

#pragma mark - AutoLayout

- (CGSize)intrinsicContentSize {
CGSize containerSize = _innerContainer.size;
if (!_verticalForm) {
containerSize.height = YYTextContainerMaxSize.height;
if (containerSize.width == 0) containerSize.width = self.bounds.size.width;
} else {
containerSize.width = YYTextContainerMaxSize.width;
if (containerSize.height == 0) containerSize.height = self.bounds.size.height;
}

YYTextContainer *container = [_innerContainer copy];
container.size = containerSize;

YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:_innerText];
return layout.textBoundingSize;
}

#pragma mark - @protocol UITextInput optional

- (UITextStorageDirection)selectionAffinity {
Expand Down