I am programmatically writing to a UITextView a comma separated string.
Example: NSString* str = #"cat,dog,big dog,kitten".
On [textView setText:str]; I get the results as:
cat,dog,big
dog,kitten.
I don't understand why is the space getting converted to a line break. Any idea?
the space gets converted to a line break, because the text did not fit into one line. This line break mode cannot be disabled, or changed. But you can rise the width of the textview.
Related
Under certain circumstances, UILabel seems to bring an extra word to new line even when there is enough space for it, for example,
If one more word is appended,
Even if I force the width of the label to become something like below, it still moves the word consists of "c"s to the next line,
I've tried twisting the configuration of the UILabel, but seems it behaves the same unless I set the line breaking mode to character wrap, below is the configuration for the above cases,
And the constraints (in the first two cases, the trailing ),
Is there any reason for this particular behaviour and can I fix this? It looks weird in this way leaving that space emptied.
this is the default behavior since iOS 11, to fix orphaned words. No way to shut it off
to fix it
use the text as attributed text
or
use UItextview and turn of the scroll, edit option
or
use the custom label here
Get each line of text in a UILabel
You should set the line break to character wrap, because the letters after the space will be recognized as a word.
Hey I know this is late but I just figured out that you can cheat the system by adding a bunch of spaces at the end of the text.
If text of UILable may be changed, then it's still possible to use quick-dirty hack with "\n" - new line symbol.
Text "Aaaaaaaaaaaaaa bbb cccccccccc\ndddddd" will force UILabel to display:
Aaaaaaaaaaaaaa bbb cccccccccc
ddddddd
In Interface Builder new line can be inputted with Ctrl + Enter
If u use wordWrap, it tries to keep words in full form, as a result of this, it goes to next line. If you use character wrap, it will break on characters, and push the chars onto next line.
For Example:-
My name is ABCXXXX and I (have space here)
love myself.
Solution:-
Use NSMutableAttributedText and write love\n. It will make the "love" be in the space myself in the next line.
I just use the custom Uilabel in a tableview which i have given a some text lines from my sqlite table.I set label.numberoflines=0;It wraps but second line appear one space before first line. How to get the second line in the same x position which the first line is.
Make sure that your UILabel is left aligned:
yourLabel.textAlignment = UITextAlignmentLeft;
or do it in ib if you're using it.
If I have a UILabel of a certain size, with line break mode set to WordWrap and numberOfLines = 0 (so it grows depending on the amount of text), is there a way to determine what characters are on each line of the label?
So if i have the text "All People Seem To Need Data Processing" as text on the label, and assuming it displays like this on screen
All People
Seem To
Need Data
Processin
g
is there a way to know the text on each line? or the width of each line?
Line 1 : All People
Line 2 : Seem To
Line 3 : Need Data
Line 4 : Processin
Line 5 : g
How about using NSString's sizeWithFont? Do up to each word until you get a number bigger than the label's width. Then chop those words and do again for the next line.
I have given an answer regarding same query How to get text from nth line of UILabel?.
There is a method, Just call it. It will return an array of each line. Happy Coding :)
I am trying to use this method to draw a string into a custom UITableViewCell.
[self.text drawInRect:TEXT_RECT withFont:font lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];
The problem is that if the text is too long, the text is actually tail truncate but it doesn't display the "..."
If I use the drawInPoint
[self.text drawAtPoint:CGPointMake(60, 0) forWidth:200 withFont:font minFontSize:15 actualFontSize:nil lineBreakMode:UILineBreakModeTailTruncation
baselineAdjustment:UIBaselineAdjustmentAlignBaselines];
Then, I get the "..." but now it make all of my text one line, so the quite long text will get truncated too soon. For example:
If I have the text "Hello all, here is my first book". If I use drawInRect, then I can display it in 2 lines, but if I use drawAtPoint, I only see the first line like : "Hello all, here ..."
So, any help to make either method work will be appreciated
UILineBreakModeTailTruncation only truncates the last line of text. Is TEXT_RECT big enough to hold multiple lines of text? What appears to be tail truncation might just be a rect that isn't tall enough.
I need to know how to add a linebreak in plain text such as UILabel.
Soli...there is an amendment at here....
The linebreaks will added on the plain text on SMS or any notification alert message.
So, the "escape sequence" can used as well ?
Thanks
set the property numberOfLines of the label to 0. Then,
yourlabel.text = #"Line 1\nLine2";
will display as:
Line 1
Line 2
The escape sequence "\n" adds a newline.
#"Line one\nLine two" will display as
Line one
Line two
I haven't tried this, and I'm not sure if it'll display properly, but have you tried putting \n in your NSString?
myLabel.text = #"First Line\nSecond Line";