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?
Asked
Active
Viewed 4,802 times
2 Answers
7
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.

iwasrobbed
- 46,496
- 21
- 150
- 195
-
But the text does not even go 3/4 the way across the line. Some of them get cut off without even taking up half of the cell. None the less, I will try your suggestion. Thank you. – Oh Danny Boy Jun 14 '10 at 20:18
-
This shortened the text so it fit in about half the cell. The other half remains blank (the right half). – Oh Danny Boy Jun 14 '10 at 20:41
-
Right... it's not the size of the cell that's the issue. You can have a cell that is 320pixels wide and a UILabel on that cell that is 20pixels wide. It's all based on the width of the UILabel that is within the cell (again, I'm assuming it's a UILabel since you haven't stated otherwise). How are you laying out the label? Are you sure another label isn't overlapping the first one and cutting it off? – iwasrobbed Jun 14 '10 at 20:49
-
This is correct. Used http://stackoverflow.com/questions/446405/adjust-uilabel-height-depending-on-the-text/446864#446864 as a reference. – Oh Danny Boy Jun 14 '10 at 21:07
-
For information on accessing the custom cell created, check http://stackoverflow.com/questions/3054881/access-custom-label-property-at-didselectrowatindexpath – Oh Danny Boy Jun 16 '10 at 17:29
-
1You have a typo. the property should read `adjustsFontSizeToFitWidth`. - you are missing the 's' after 'adjust'. – Austin Aug 30 '13 at 02:37
2
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.

jer
- 20,094
- 5
- 45
- 69
-
Also you can insert \n new line characters into your screen and set the numberOfLines property to however many lines there are, tho u can also set it to 0 and it will auto adjust – Daniel Jun 14 '10 at 17:43
-
I tried that, it puts the string on two lines. This is not the effect am looking for. I want the string to appear on one line. The largest string is only three words. – Oh Danny Boy Jun 14 '10 at 18:09
-
Three words can be as few as 5 characters, or as many as N characters. You need to figure out how long your string of words can be, and act accordingly. – jer Jun 14 '10 at 18:59
-
The longest string is 18 characters. I cannot figure out a way to adjust the width or max string size for the label. The only methods I come across are regarding cell height. – Oh Danny Boy Jun 14 '10 at 19:51
-
You need to set up the frame of the UILabel (frame property) to a frame big enough to hold your longest string. Create one with CGRectMake() and then set the frame of the label. – jer Jun 14 '10 at 20:37
-
This is correct. Same solution as poster above. Thank you for your help. – Oh Danny Boy Jun 14 '10 at 21:08