I have a simple app with a UITextView embedded into a UIScrollView. Interface Builder won't let me add multiple newlines for spacing; when I hit return it sees that as "end of input" rather than appending the newline to the UITextView.
How can I get it to accept newlines for spacing?
Much simpler (and more IB based) than previous answers:
Just Alt + ENTER It will send a newline to the UITextView.
Write up your text in TextEdit, then copy/paste it in.
As sbwoodside said, a text editor is the easiest way.
That said, ff you need more control, or it isn't quite working, don't use IB. Ideally, if you need any type of formatting for a long sting of text, do it programmatically.
Formatting in IB is horrible. I tried to add some "terms and conditions" in a UITextView and it was a real pain.
In the end it is easier than messing with IB...
In IB Shift+Alt (Option)+Enter is as New paragraph
Related
When displaying a paragraph with some long strings without line breaks in an UIWebView, the size of the character is too small for reading, as show in the following pic. Is there anyway to automatically add line breaks in the long strings as in the UILabel? Thanks in advance!
ps. the UIWebView is used to display an email body.
set the css as : style="word-break:break-all" to solve this problem
Simply NO. UIWebView is made to parse HTML-Markup. The breaking has to be done there. \n will do it.
Other than that, you should rethink your HTML-Box-Model being responsive.
If you only want to display text, then use UITextView instead of UIWebView and switch to UIWebView, if its HTML. I think Mail.app on iOS does it like that. UITextView text is appropriately scaled.
In my UITextView whenever I have been giving multiple spaces a dot is adding at the end of the word. As I am using that for getting email id, I don't want any dots, How to avoid this?. I have added that UITextView in IB. Do I need to do any changes there?
It's a keyboard setting. Go to settings->general->keyboard and disable "." shortcut. It inserts period if you add two consecutive spaces.
In interface builder, set the keyboard option to E-mail address.
I've a UITextView, its quiet big, I sized it so it could fit 4 lines of text, so if the user wants to write a long note it can be read while its being written.
The problem is that text stays on the top line and it scrolls horizontally rather than wrapping around and dropping down to a line below it. Like you see when you write a text message on your phone.
Is there anything that can be done to get a UITextField to act like this? Or am I required to use an editable UITextView instead?
Looking at the docs it would seem UITextView cant provide the functionality I need.
Many Thanks
-Code
HI,
I do'nt think , It could be possible by using UITextField (support single line),You will have to use the UITextView (for multiline text) .
See the below tutorial , It grow at runtime while the user type the text using keyboard and can expend till certain line ...
http://www.hanspinckaers.com/multi-line-uitextview-similar-to-sms
If it is an IBOutlet than you can just enable vertical scroll and remove horizontal scroll from scrollers.
Hope this helps.
I have spent a few days trying to get around the limitations with UITextField, namely no text wrap and number of lines. I have created a UILabel, which is used to display the text entered in UITextField and does all the formatting stuff properly. The UITextField is hidden and the user sees all the text entered only in UILabel as it's being entered.
Everything is working perfectly except for the lack of a cursor on the UILabel to show the user where the next character typed into the field will show up.
I have experimented with using various characters as cursors on the label. But there is no getting around the fact that it is not the standard blinking cursor indicator on the iPhone and so the whole thing just looks wrong.
Before I abandon ship and go for a UITextView (with its own set of issues) I was wondering if anyone has any ideas as to how a blinking cursor can be added to the text field on a label text.
Thanks in advance.
Your approach has other issues which make it worth rethinking the strategy.
How does selection look like?
copy + paste?
Do you handle right to left languages?
Auto correction?
The list is certainly longer, but I think it's enough to consider other solutions. But I agree that all of UIKit's text handling is a bit poor.
If you don't need to support selection, copy and paste, and only need multiline input, you could use a | character and animate it as if it were blinking... either that or perhaps a custom overlay view on top of the label, that would implement the cursor drawing, animation and positioning based on the length of the string and the font used.
– sizeWithFont:forWidth:lineBreakMode:
– sizeWithFont:constrainedToSize:
– sizeWithFont:constrainedToSize:lineBreakMode:
– sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
may help to achieve just that.
So what are the issues preventing you from going to a UITextView? It seems possibly easier to address those.
I'm developing an application for the iPhone where some text is shown in a UITextView. I want to search for a specific word in the text and then show the text with that specific word colored. If anyone can help me solve this, I'll be very glad.
UITextView does not allow any formatting of the text within it. If the text is static (i.e. doesn't need to be edited), use a UIWebView instead; that will allow you to apply HTML formatting.
If a web view isn't an option, your best bet will be to try to calculate where the text in question will fall in the text view and then draw some sort of highlight around it. NSString has some methods to calculate how much space you need to draw a given string on screen; by being very, very clever with those methods, you may be able to work out where the word you're trying to highlight is. Unfortunately, this will not be at all simple.
If you do come up with a solution, everyone here would probably love to hear about it!