Devide text to UITextViews - iphone

I have long text and 2 textViews.
I need to insert this text to 2 textViews(they have no scrolling).
It's like book pages(first page is a one textView, second page is a another textView).
So, question is: how to determine which text length I need insert to first textView?

You can set the complete text to the first textView, calculate the visible text range and set the remaining text to the second textView. An alternative is to manually calculate the range of the text that will be visible in the first textView, however it requires ugly recursion with sizeWithFont that i can't believe is so fast, i'd follow the first way.
See this answer to learn how to get the visible text range.

First figure out length of each line, font, and how many lines you can fill into the each textview. Use following to do this
CGFloat stringWidth = [text sizeWithFont:[UIFont fontWithName:your_textview_font_name size:your_textview_font_size]].width;
Then use substrings operation.
Shouldn't be difficult to do this!

Related

How to correctly put labels on one line

I have three UILabel with different font and I want to put then on one line.
The problem is that as the text length of those label is not fixed, I have to change the location of the second and the third label according to the text length of the label before, otherwise the text will be overlapped.
I plan to set the location according to the text length of the label before and I have to recognize the uppercase and the lowercase. I have to consider more if I use other language.
I want to know is there a better method to solve this problem, thanks!
CGSize size = [#"SomeString" sizeWithFont:[UIFont systemFontOfSize:20.0]];
CGFloat width = size.width;
Look into the CoreText Framework. You'll be able to have much more control over your text characteristics than using UILabels.
Developer Reference:
https://developer.apple.com/library/mac/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Introduction/Introduction.html
Tutorial:
http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text

Display text with one word appearing after another word effect

I want to display a label or uitextview with text in a manner that text will appear slowly with one word at a time. I mean first it will display first word then second and then third and so on…
I'm not familiar enough with core-animations, but this could be acheived by using a simple NSTimer and on each interval append the UILabel's text

UITableView cell text is cut off

I am having a problem with the UITableview cell cutting off strings whose characters are more than 12 chars. Any ideas why this would occur? I have not made a custom cell at all. I cannot find any solution to this problem through a Google search. Any ideas?
You should be able to set the label properties to re-size the font based on the label's contents using adjustsFontSizeToFitWidth. This will essentially decrease the font size to make the text fit all on one line.
Your cell likely contains a label, which in turn is set to given bounds. What you need to do is ensure that your label is the same size as your longest string, or bigger than it.

UILabel and superscript

I have two strings:
a variable length piece of text
another string with numbers that
point to a reference
In my view, the first piece of text is displayed in a UILabel, I adjust the size of the label to accomodate the size of the text. This means I cannot just place another UILabel on the screen, at least not without repositioning it...somehow.
I need to be able to put the second piece of text so it appears to be at the end of the sentence - and superscripted
I really have no idea how to achieve this!
My rather dodgy solution was to enter unicode characters for the superscripted numbers.
Not a great solution but it worked.
The simplest way would be to use two different UILabels. A better solution might be to draw both strings using -drawInRect:withFont: in a custom view's -drawRect: method.

Creating a fixed formatted cell in UITableview

I want to have a tableview create rows that look like this:
value1 item1 container1
value10 item10 container10
value100 item100 container100
value2 item2 container2
What I am trying to show is that the first word (value) will have a set length of 12 and then the second word (item) will have a set length of 10 and then the last word (container) is just tagged on at the end.
I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted structure like this.
You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)
Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.
There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.
It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.
Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.
You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.