Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.
Merged
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
22 changes: 19 additions & 3 deletions Source/SLKTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,26 @@ - (UIColor *)placeholderColor

- (NSUInteger)numberOfLines
{
CGFloat contentHeight = self.contentSize.height;
CGSize contentSize = self.contentSize;

CGFloat contentHeight = contentSize.height;
contentHeight -= self.textContainerInset.top + self.textContainerInset.bottom;

return fabs(contentHeight/self.font.lineHeight);

NSUInteger lines = fabs(contentHeight/self.font.lineHeight);

// This helps preventing the content's height to be larger that the bounds' height
// Avoiding this way to have unnecessary scrolling in the text view when there is only 1 line of content
if (lines == 1 && contentSize.height > self.bounds.size.height) {
contentSize.height = self.bounds.size.height;
self.contentSize = contentSize;
}

// Let's fallback to the minimum line count
if (lines == 0) {
lines = 1;
}

return lines;
}

- (NSUInteger)maxNumberOfLines
Expand Down