Formatting in a UITextView - iphone

im having problems with formatting for a UITextView. my app pulls in XML, saves some of it to a string , and then displays the text in a UITextView.
it understands if you put a return in there, and it starts a new line. but i want to put paragraphs in there, any idea how i can pass that information without doing multiple UITextViews
Thanks :)

If you are converting to text from XML content, then it is probably easier to use a UIWebView and format using html.
If you want total control of formatting, then you need to move to using Core Text (3.2/iPad).

Related

How to stop Textview from also copying the formatting when copying and pasting?

Whenever I paste something into the Textview from an external source, it also copies the original formatting of the text. I want my swift app to ignore the original formatting, and instead format it according to what the Textview has been set to.
How would I achieve this?

Add line breaks when displaying a long string in UIWebView

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.

Custom Font in Text View/Interface Builder

I hope this is a really simple question, but it's stumped me. Basically, I have a huge amount of text that I'm using the text view for. For the most part, it's just the system font. However, I would like to format "headers" every few paragraphs in the large chunk of text with a custom font (that I've added to my project) and background color. How do I target small pieces of text within the text view?
If it were just a small piece of text, I would just add a label and do it with code, but since this a huge piece of text, what's the best way to do it?
Thanks!
If you load a large amount of static text with formatting, I suggest you save it as a html file and load it into UIWebView.

Formatting Text Data Stored in SQLite3

I have paragraphs stored in SQLite cells, of which I wish to make a few important words bold-face. I take it I must make this formatting while entering the data into the database; how do I accomplish this? Also, when retrieving the data in Objective-C, how do I ensure it retains its formatting (programmatically) for use in a UITextView?
Edit: So not necessarily UITextView, but whatever works to display formatted text.
UITextViews do not handle formatting styles.
The only way to show styles is to display using a UIWebView and using markup (bold tags for instance sometext)
At the same time you can save the marked up text in your SQLIte DB as normal.

How to upload contents of a file to a UITextView?

I have about twenty UITextViews and corresponding .txt files. What I want is to make each UITextView take the contents of the corresponding file and display it.
Moreover, the text is formatted and it contains some formulas (copy/pasted from Grapher). I've heard about displaying formatted text in UIWebView, but I haven't found a clear explanation anywhere.
Thanks in advance!
Text files normally don't contain formatted text.
If by "formatted" you mean "html" then yes, you will want to use UIWebView. Basically you will convert the text to an HTML document, and then use the web view to display that document. There are several example projects available from Apple that show you how to use UIWebView.
Displaying formula in a UITextView will be difficult as the character rules for formula are completely different from language text. You could generate HTML to display it that but that is difficult as well.
I think your best bet would be to draw the formula to an image and then display the image. That is the traditional way to handle the display of formula.