how to set text to split into 2 lines in swift uiTextField - ios

I have a uiTextField with dynamic text.
How can I set it via the editor to split the text into 2 lines (or more)
if text doesn't fit in the uiTextField width?
Is there a way to do this not programmatically?
Now text is seen as
"This is a long line" ===>
"This is...."
and I want it to be
"This is a
long line"

UITextField is one line only. You can not have multi line content in UITextField. If you want to have multi line then use UITextView.

As Vishnu said you need to use UITextview for multiple row textfield
also add a "\n" where you want to break the string into the next line like so
"This is a\nlong line"

Related

UIButton word wrap doesn't work when entering text?

I've got a UIButton, it's a simple segue to another page.
I've set Title to attributed and then selected word wrap. This works fine, the second word wraps down to the next line.
However, it is all left justified. When I select "Align Centre" (using the buttons just under the "Title", the word wrap no longer works and simply runs .... so you can't see it all. (e.g. "next pa" instead of "next page")
Am I missing something here? It seems like such a trivial thing to do! There's an old answer here can't get word wrap to work on UIButton but it's both old and uses code - surely you don't need code to centre the button text if you want to word wrap it to 2 lines!?
I've set Title to attributed and then selected word wrap. This works fine, the second word wraps down to the next line. However, it is all left justified.
Once you've decided to use an attributed string, you must do everything with the attributed string. So give your attributed string a paragraph style that centers the text.
let para = NSMutableParagraphStyle()
para.alignment = .center
para.lineBreakMode = .byWordWrapping
let s = NSAttributedString(
string: "Hello World", attributes: [.paragraphStyle : para])
self.button.setAttributedTitle(s, for: .normal)
You will also need to set the button's title label to allow multiple lines.
self.button.titleLabel?.numberOfLines = 0
Result:
surely you don't need code to centre the button text if you want to word wrap it to 2 lines!?
Not to center it, no; you can set the centering in the storyboard. So you could eliminate the first batch of code and configure it in the storyboard. But you must use code to turn the title label into a multiline label:
self.button.titleLabel?.numberOfLines = 0
There is no way to do that in the storyboard, because you have no access to the title label there.
I've just been playing round with this and I've found it works if you set it to 'character wrap' rather than 'word wrap' once you've selected centre alignment.
If anyone has a better solution please add it, as I guess this might have issues if you slightly change the width etc when using auto layout for different screen sizes etc if you want it to adapt its width so this might not be the best solution but it does work

how to make entered text to be one line of text?

I am trying to make a notification section using table view, view the cell is tapped then it will show the detail of the notification info like this
as we can see in the first picture (table view cell), the text (the text content, not the title) is clipped. I don't think this is an autolayout issue, since I have set the autolayout constraint like below
I hope that I can get the table view cell like below, some context will also be displayed in 2 lines in the label.
I suspect this is because it has entered text
Dear All,
(enter)
Perlu kami informasikan bahwa ..........
maybe thats why i get
Dear All, ......
could you please help me ? Thanks in advance
The entered text has embedded newline \n characters. That's why you only see the first "line" of the text, followed by the clipping ....
To fix that, replace the newline characters with spaces:
// example
let ls = "This is\nSome text"
let t = ls.replacingOccurrences(of: "\n", with: " ")
print("t", t)
// output is "This is Some text"
So, when you want to display the "abbreviated" text, replace the newline chars. When you "expand" the cell, you'll need to show the original string.

UILabel text wrong new line when has special character

Details of the issue :
When display text inside UILabel and almost the text fill complete line, if you add one more character with spacial character such as "ً" (check number 1) , it cuts first letter of text and put it in line alone(check number 2) and the rest of text in other line (check number 3)
Please note that the issue happening in the Facebook app and iOS note app
Try setting the linebreak mode to word wrap.
This may help.
Another option, try using textview instead of label.

swift dynamic numbers of line

i work with ios 8 swift an have a textfield into a table cell.
if i put in this textfield a short text, i have no problems.
but is there a long text, the end of the this will cut, like this:
"This is the Exmaple of ..."
how can i set dynamic a second line in to my textfield, if the text will be to long for it?
i do not have any code because i dont know how i can solve this situation.
UITextField can contains only one line of text. The component you need is the UITextView.

How to specify two line label in iOS Attribute Inspector

I am creating a View (i.e. I went to New -> iOS -> User Interface -> View). I want to have a two line UILabel in my View. But when I set the label's text as Line one here this. \nAnd line 2, the entire literal shows up in one line. Even though I specify that the label should have two lines. How do I make it two lines?
Don't put \n in the text, but rather press Alt/Option + Enter

Resources