File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -162,10 +162,26 @@ - (UIColor *)placeholderColor
162
162
163
163
- (NSUInteger )numberOfLines
164
164
{
165
- CGFloat contentHeight = self.contentSize .height ;
165
+ CGSize contentSize = self.contentSize ;
166
+
167
+ CGFloat contentHeight = contentSize.height ;
166
168
contentHeight -= self.textContainerInset .top + self.textContainerInset .bottom ;
167
-
168
- return fabs (contentHeight/self.font .lineHeight );
169
+
170
+ NSUInteger lines = fabs (contentHeight/self.font .lineHeight );
171
+
172
+ // This helps preventing the content's height to be larger that the bounds' height
173
+ // Avoiding this way to have unnecessary scrolling in the text view when there is only 1 line of content
174
+ if (lines == 1 && contentSize.height > self.bounds .size .height ) {
175
+ contentSize.height = self.bounds .size .height ;
176
+ self.contentSize = contentSize;
177
+ }
178
+
179
+ // Let's fallback to the minimum line count
180
+ if (lines == 0 ) {
181
+ lines = 1 ;
182
+ }
183
+
184
+ return lines;
169
185
}
170
186
171
187
- (NSUInteger )maxNumberOfLines
You can’t perform that action at this time.
0 commit comments