UITextView word wrap breaks in the middle of a word - ios

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?

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

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.

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.

Related

iOS Autoshrink not working on single word in UILabel

Using autolayout to have a multiline UILabel auto size the text to fit does not work for single words.
Here is how storyboard is set up:
Here's the problem.
This does not display properly:
But this does:
I have adjusted every setting in the storyboard. I have changed all of the Line Break settings (wrap, truncate, etc), I have adjusted # of lines, I have made text plain vs attributed, I've changed font sizing and scaling, everything. What am I missing? Why does "California" get cut off instead of shrinking to fit? I've seen many other posts on SO and haven't yet found a solution (which needs to be compatible back to iOS 9)
Your label is being filled both horizontally and vertically until it runs out of space, then it starts shrinking the text to fit. In the one word example it breaks the word into two lines because there is vertical room.
Do you know in advance or can you calculate in the app when you have only one word in this label? If so you can change the number of lines to 1 instead of 0 so the app will keep the contents on one line and shrink this word.

Place Text in Top part of UIlabel

I have a UILabel that covers most of the view. When I place text in the label, the text is center in the middle of the label. I have tried everything by playing around with the options in the attributes inspector, however the text wont start in the top area of the label, instead it appears in the middle of the label.
Is there any way to places the text in the top part of the label??
(If someones is wondering, yes I want the UILabel to cover most of the view because some texts are longer then others, and some are shorter, and I would prefer the text to be placed on the top part and not the middle of the UIlLabel.)
UILabel has an intrinsicContentSize matching the text contents. If you don't constrain the height, then it will automatically adjust. So you don't need to make it cover the entire view.
Instead, tag it onto the top with a fixed distance. Specify the bottom distance with greater-than-or-equal. This way the label can grow until it reaches the lower limit and then the text will begin to be truncated.

How to make UILabel as narrow as possible with multiple lines?

I have a UILabel that's got 2 lines of text. (I want to force 2 lines). I set some constraints on it so that it's got certain insets on the left and right. The text always comes out where the top line is a lot longer than the bottom. I want both lines' width to be as close to the other as possible. How can I do this? I have localization so I can't just move the insets in.

Xcode label causes line break in middle of word

I've been working with a label on a storyboard and can't seem to get it to behave correctly. I have my lines set to 0 because I display a couple different things in the label, depending on what the user clicked before. 3 or 4 words will display fine and on multiple lines, but when I get to a larger single word it will break the word in half. I don't won't it to do this, I just want it to resize and stay on a single line if it's only one word. Any ideas how to do this? I already have it working so that it will auto resize long text to fit there, the only problem is this.
If a UILabel is too small in its width, it cuts off the last part of the text or breaks its content into another line. As one word does not break into half automatically it can't be displayed entirely and therefore is cut off at its end.
In order to solve your problem I have some suggestions:
Change the number of lines to at least 1
Update your frames
Resize the UILabel so it can display the entire word.
Take a look at your constraints, as they might force the UILabel to resize under certain conditions.
I hope this might help you.

How to handle long text UILabel

I have a view which has a lot of labels. Some of them get the text set dynamically. Sometimes the text is to long to display it within one line. I know how i can display the text in multiple lines. My problem is that when i do display the text in multiple lines then the margins are broken between the labels. Sometimes a label even swapes into the content of the next label.
I want to avoid fixing this "by hand" (repositioning of all other elements). Maybe Autolayout can fix this, but sadly i'm not able to use it for now. But it would be a good argument to convert my project from springs&struts into autolayout. However, maybe there is another way to fix this issue. Would be nice if somebody can help me out. Thanks in advance!
You can use sizeWithFont:constrainedToSize:lineBreakMode: to calculate the height which will be required by each of the labels. You should use this in a loop which iterates over each label in the order they should appear on screen. As you go, increment the y position by the height of the current label and the margin. Each label will now have the correct position and at the end of the loopy will hold the full required height.

Resources