Creating multiline cell in UITableView

by alex 7. September 2010 22:35

- (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"BigListCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc]

initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:CellIdentifier] autorelease];

CGRect labelFrame =

CGRectMake(CGRectGetMinX(cell.frame)+50,

  CGRectGetMinY(cell.frame), CGRectGetWidth(cell.frame)-150,

  CGRectGetHeight(cell.frame));

UILabel *label = [[UILabel alloc]

  initWithFrame:labelFrame];

label.numberOfLines =0;

label.tag = 100;

label.lineBreakMode = UILineBreakModeWordWrap;

label.autoresizingMask = UIViewAutoresizingFlexibleWidth

|UIViewAutoresizingFlexibleHeight;

[cell.contentView addSubview:label];

[label release];

}

UILabel *label = (UILabel*)[cell viewWithTag:100];

label.text = @"Long Long Long Long Long Long Long Long Long Long Text"; // Put your text there

}

 

- (CGFloat)tableView:(UITableView *)tableView 

heightForRowAtIndexPath:(NSIndexPath *)indexPath{

CGSize constraintSize = CGSizeMake(170.f, CGFLOAT_MAX);

UIFont *theFont  = [UIFont boldSystemFontOfSize:15.0f];

CGSize theSize = [theText sizeWithFont:theFont

constrainedToSize:constraintSize

lineBreakMode:UILineBreakModeWordWrap];

return theSize.height+20;

}

Resize UITableView to fit toolbar

by alex 12. May 2009 16:03

CGFloat toolbarHeight = 50;

CGRect mainViewBounds = self.view.bounds;

[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),

CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),

CGRectGetWidth(mainViewBounds),

toolbarHeight)];

 

 

UIView *footerView = [[[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 

CGRectGetMinY(mainViewBounds), 

CGRectGetWidth(mainViewBounds), 

toolbarHeight+5)] autorelease];

 

tableView = [[UITableView alloc

initWithFrame:CGRectMake(mainViewBounds.origin.x, mainViewBounds.origin.y, mainViewBounds.size.width, mainViewBounds.size.height - toolbarHeight -5

style:UITableViewStyleGrouped];

tableView.delegate = self;

tableView.dataSource = self;

tableView.tableFooterView = footerView;

tableView.backgroundColor = [UIColor clearColor];

[self.view addSubview:tableView];


Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen