I have an app with a handful of UITextView
s of various sizes. It appears that if a UITextView
small enough has a font.pointSize high enough, there's no way to add a space after the text is big enough to fill the text view.
For example:
I'm trying to figure out what was going on here, I starting typing my usual debug string, I typed "What" hit the space key and no space appeared (but this is usual). I typed "the" and the looked like it was tacked right onto the end of the previous word. Sure enough, there was no space. I could go back and add the space just fine and once I do add the space, I can add other spaces as word wrapping then becomes effective.
Another mysterious behavior is that when you double tap space, it doesn't add a period to the end. It replaces the last character with a period. So, "What" + space + space becomes "Wha."
Now, I'm doing some interesting things with the font size like I'm automatically resizing the font so that the text fills the space provided within reasonable bounds, but when I disable that, I can still reproduce the behavior. The only difference then is that instead of fitting on one line, the word wraps to the next line.
For example, if I type "What" + space + "the" it comes out "Whatthe" with "What" on the first line and "the" on the second (though I can only see the tops of the "the." Further, here's some log information from the textViewDidChange:
.
Character textView.text.length
--------- --------------------
W 1
h 2
a 3
t 4
<space> 4
t 5
h 6
<space> 7 <---- Here's a wierd one . . . now spaces all
? 8 work fine unless it's resizing
Another mysterious behavior is that when you double tap space, it doesn't add a period to the end. It replaces the last character with a period. So, "What" + space + space becomes "Wha."
That is not mysterious. That means that your UITextView
uses autocorrection.
Fix:
UITextView *txtView; // your UITextView
[txtView setAutocorrectionType:UITextAutocorrectionTypeNo];
About spaces... as space is not a drawable symbol, your UITextView
can't measure is size (width differs with different alignment), so your UITextView
's contentSize
property won't be changed and behaves mysteriously. You should set contentSize
manually (you can easily calculate size of your NSString
with sizeWithFont:
method).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With