View Full Version : Custom table cells
r00li
Sep 19, 2009, 05:19 PM
I have created a custom table cell in interface builder that I am using. I have two problems with it.
The first one - I am using grouped table View and the corners of the cell are not rounded.
Second in that table cell I have a label on the bottom. I want to resize the whole cell and the label if there is too much text to fit. Text is loaded from an NSArray. But I don't know how the resize the cell and the label so that the text can fit.
This is how the cell looks like:
----------------------
|.........| some text
|image|
|.........| other text
resizable text
-----------------------
dejo
Sep 19, 2009, 05:53 PM
Second in that table cell I have a label on the bottom. I want to resize the whole cell and the label if there is too much text to fit. Text is loaded from an NSArray. But I don't know how the resize the cell and the label so that the text can fit.
To resize the cell, look into the UITableViewDelegate method tableView:heightForRowAtIndexPath:.
r00li
Sep 19, 2009, 07:09 PM
I know how resize the cell. Problem is with resizing the label and then resizing the cell. I must resize the label to fit the text before I can resize the cell.
r00li
Sep 19, 2009, 07:27 PM
Yust found a simple method on the internet and simplified it a lot.
CGFloat size = 15; //Font size
//Calculate the expected size based on the font and linebreak mode of the label
CGFloat maxWidth = [UIScreen mainScreen].bounds.size.width - 50;
CGFloat maxHeight = 9999;
CGSize maximumLabelSize = CGSizeMake(maxWidth,maxHeight);
CGSize expectedLabelSize = [[detajli objectAtIndex:3] sizeWithFont:[UIFont systemFontOfSize:size] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap];
return expectedLabelSize.height + 150;
//[detajli objectAtIndex:3] is a NSString
Now the remaining problem are the section corners. For some reason they are not rounded. They are flat and it looks bad.
PhoneyDeveloper
Sep 19, 2009, 08:17 PM
If you inset the views that are at the left and right edges of the cell several pixels you should see the rounded corners. If that doesn't work show a screenshot.
dejo
Sep 19, 2009, 08:49 PM
I know how resize the cell.
Sorry, I wasn't able to detect that based on your first post.
r00li
Sep 20, 2009, 06:39 AM
If you inset the views that are at the left and right edges of the cell several pixels you should see the rounded corners. If that doesn't work show a screenshot.
Great that worked!
Sorry, I wasn't able to detect that based on your first post.
I should probably improve my writing style!:rolleyes:
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.