Skip to content

Commit f1434f2

Browse files
committed
merge ibireme#951, make YYTextView support AutoLayout
1 parent 46e211f commit f1434f2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

YYText/YYTextView.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,8 @@ - (void)setAttributedText:(NSAttributedString *)attributedText {
21962196
if (!_state.insideUndoBlock) {
21972197
[self _resetUndoAndRedoStack];
21982198
}
2199+
2200+
[self invalidateIntrinsicContentSize];
21992201
}
22002202

22012203
- (void)setTextVerticalAlignment:(YYTextVerticalAlignment)textVerticalAlignment {
@@ -3644,6 +3646,25 @@ - (NSArray *)selectionRectsForRange:(YYTextRange *)range {
36443646
return rects;
36453647
}
36463648

3649+
#pragma mark - AutoLayout
3650+
3651+
- (CGSize)intrinsicContentSize {
3652+
CGSize containerSize = _innerContainer.size;
3653+
if (!_verticalForm) {
3654+
containerSize.height = YYTextContainerMaxSize.height;
3655+
if (containerSize.width == 0) containerSize.width = self.bounds.size.width;
3656+
} else {
3657+
containerSize.width = YYTextContainerMaxSize.width;
3658+
if (containerSize.height == 0) containerSize.height = self.bounds.size.height;
3659+
}
3660+
3661+
YYTextContainer *container = [_innerContainer copy];
3662+
container.size = containerSize;
3663+
3664+
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:_innerText];
3665+
return layout.textBoundingSize;
3666+
}
3667+
36473668
#pragma mark - @protocol UITextInput optional
36483669

36493670
- (UITextStorageDirection)selectionAffinity {

0 commit comments

Comments
 (0)