14

I have an app with a handful of UITextViews 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
Irfan
  • 4,301
  • 6
  • 29
  • 46
D. Patrick
  • 2,894
  • 26
  • 37
  • Have you raised it in [Apple Bug Reporter](http://bugreporter.apple.com)? – iDev Feb 06 '13 at 03:17
  • The more I looked at it, the more I felt like I tested pretty thoroughly and thus the more reasonable it was this is a bug. I tried with a smaller font and longer word and got the same results. I submitted a bug report. In the meantime, I'm using a smaller font hoping to reduce the liklihood that my users will encounter this situation (i.e., maybe they won't start with long words) so that I can get a release out, but I don't feel great about it as the problem still exists. – D. Patrick Feb 06 '13 at 04:40
  • Jst had this problem :( – Nico Prananta Feb 16 '13 at 16:23
  • I did file a bug report and they asked me to post a sample app. I did and I'll let you guys know what comes of it. – D. Patrick Feb 16 '13 at 20:55
  • I have verified that this bug will likely be fixed in the next few months. – D. Patrick Jul 01 '13 at 20:53
  • It appears this was fixed in iOS 7. – Mike Dec 28 '13 at 00:56
  • I had got the same problem in ios 7. but could not detect the reason. It might be a bug. – Rinku Mar 06 '14 at 06:34

1 Answers1

1

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).

Dennis Pashkov
  • 934
  • 10
  • 24
  • 1
    Well, automatically adding the period is a desired behavior. Usually, when that period gets added, it appends to the end of the string rather than replacing the last character. When I made the demo app, I did it without any resizing. When a single word reaches the edge of a text area (even without dynamic resizing), the undesired behavior still exists. – D. Patrick Apr 29 '13 at 13:09