UITableView cell text is cut off - iphone

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.

Related

UILabel: Get actual font size with adjustFontSizeToFit

I have two labels in my layout.
I want the font size to adjust to fit the label bounds.
I set to true the UILabel adjustFontSizeToFit.
Moreover a need the two labels to have the same font size. So I added an auto-layout constraint to make the labels have the same size.
The issue with it is the labels do not contain the same string. Sometimes the first is longer and vice-versa. The font I use doesn't have the same width for every character which will not allow me to use a space to fill to shorter string. (This solution looks a bit ugly to me).
I tried to get the label.font.size.pointSize after the label has been displayed but the value returned is always the one I set at the beginning (before being reduced to fit).
Does anyone have an idea on how I could achieve it ?

Devide text to UITextViews

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!

iPhone: UILabel text does not fit the way i want

I have a UILabel with some text on it, what I want is if the text with the given font does not fit to the label, I want it to be first linebreaked to a second line, and if still does not fit then it should automatically adjust those 2 lines to a smaller font.
I experienced with the IB changing the settings of linebreaks and number of rows, but couldn't get what I want.
Any recommendadtions?
To my knowledge UILabel does not support auto adjusting the font when there is more than one line.
The only way I know of it to iteratively calculate a fitting font size and then to set the appropriate font manually.
Maybe the sizeWithFont: method is a solution for you:
– sizeWithFont:forWidth:lineBreakMode:
This calculates the width / height of a NSString with the appropriate font / settings

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.