How to add linebreaks in iPhone programming? - iphone

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";

Related

Unnecessary line break in UITextView

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.

Use line breaks of retrieved NSString

I retrieve an NSString from a Property list and display it in a UILabel. The NSString already includes \n s, however the UILabel just displays them as text. How can I tell the UILabel to actually use the \n s as line breaks?
Everything you type into a plist in the plist editor is interpreted as plain text. Try it... put a ' into a field and right click -> view as "plain text" and you'll see it substitutes it for '. Therefore you can't put \n into a plist because it thinks you're just typing text and will treat it as such. Instead of putting \n into your plist use Alt+Enter to get your newline. If you view this as a text file now you'll see \ns printed and new lines acctually shown in the text file.
Now when you output it it won't display \n it will just give it a new line.
Plus, as has been mentioned UITextField is only one line anyway and you probably would benefit from using UITextView.
Well, first, you are going to need a string that you can modify. To accomplish that, you can simply do:
NSMutableString* correctedPath = [path mutableCopy];
At that point, you can use -insertString:atIndex: to insert any characters you need.
You're using the wrong class here.
UITextField doesn't (for all that I know) support multi-line input. For that, you will need a UITextView (it has editing enabled by default). It should interpret \n's without any problems. It also has a lineBreakMode property, if you want to make use of that.

UITextField displays extra dot at the end of text

I saw a very strange issue with UITextField control. When typing in UITextField after typing a few characters when typing space characters it puts "." characters at the end of the string.
Can anyone know possible solution for this??
Thanks,
Jim.
Do you mean when you enter 2 spaces? If so this a feature that means you don't need to switch to the numeric keyboard to enter the full stop

How to make multi-line text on the iPhone?

Would I use a UILabel for that? Or is there something better?
It depends on what you want to achieve. If you just want a multi-line label, then you can use UILabel with the numberOfLines parameter set to something other than 1 (set it to zero if you don't care how many lines are used). If you need to let the user edit the text, then a UITextView is the way forward. Line breaks are indicated using the \n character, not the /n sequence as Emil incorrectly wrote.
You can use a UITextView, and write \n where you want the new lines.
Hey!\nHow are you?\n\n\nYOU: I am fine.\nME: That's great! will display:
Hey!
How are you?
YOU: I am fine
ME: That's great!

iphone SDK: how to add a new line char to my uitextview programmatically?

Please help me adding a line break (\r\n) programatically to my UITextView.
If you get the text from the text view, create a mutable version of the text, then add just \n, the set the text view's text, it'll work. Don't put a carriage return and a linefeed both.