16

I'm using a UITextView to present definitions which may be one or more lines long. When it does go past a lane, if often wraps in the middle of a word.

Is this normal? What can be done to prevent this?

jszumski
  • 7,430
  • 11
  • 40
  • 53
Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213
  • 3
    Can you give an example? Source code? My first guesses are: (A) Some of your words are more than 80 characters long, so UITextView has no choice but to wrap them; (B) Your lines include spaces, but they're U+00A0 NON-BREAKING SPACEs instead of U+0020 SPACEs, so they don't contribute to line-wrapping; (C) Your method of "present[ing] definitions" is suppressing proper line-wrapping somehow. – Quuxplusone Oct 01 '12 at 21:22
  • Assuming case (A) is there a way to compute the minimum width to prevent that case? – okhobb Nov 15 '17 at 21:32

3 Answers3

1

word wrap IS the default for IOS UITextView and the only reasons it fails Quuxplusone mentioned in his comment.

EITHER

  • the one word is longer (in pixels) than the textView's frame
  • the 'spaces' aren't really spaces but unbreakable spaces
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
1

It appears that this can occur when exclusion paths are too close to the edge of the UITextView. In this example accompanying this tutorial you'll notice that if you run the app and select the Interaction tab that while the oval is placed centrally words hyphenate and break naturally, if you drag it to the left edge then words break forcibly and are fragmented. But if you drag the oval half off the screen then wrapping works.

So when working with ovals you can use the trick of going off the left edge, and with rectangles, just don't get too close to the edge. Being up against it is fine.

sketchyTech
  • 5,746
  • 1
  • 33
  • 56
-1

You can do it as : UITextview having a property of enable scrolling. So the text characters limit doesn't matters. If there is more text, the textview make it scrollable. OR Make the textview height dynamic, get the string/text height and set the height of textview accordingly.