Created
October 23, 2011 08:01
-
-
Save sumardi/1307027 to your computer and use it in GitHub Desktop.
iPhoneDev - UITableViewCell dynamic height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FONT_SIZE 14.0f | |
#define CELL_CONTENT_WIDTH 320.0f | |
#define CELL_CONTENT_MARGIN 10.0f | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; | |
{ | |
NSString *text = [items objectAtIndex:[indexPath row]]; | |
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f); | |
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; | |
CGFloat height = MAX(size.height, 44.0f); | |
return height + (CELL_CONTENT_MARGIN * 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment