Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created February 27, 2013 03:56
Show Gist options
  • Select an option

  • Save romyilano/5044929 to your computer and use it in GitHub Desktop.

Select an option

Save romyilano/5044929 to your computer and use it in GitHub Desktop.
Programmatically creating UITableViewCell Autolayout and struts in code apress.com Pro iOS TableViews for iPhone
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableVIewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// configure the cell's background
UIImageView *gradient = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gradient"]];
[cell.contentView addSubview:gradient];
// configure the cell's label
UILabel *theLabel = [[UIlabel alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
// nice!!!
// grab a reference to the label's text from the tableData
theLabel.text = [_tableData objectAtIndex:indexPath.row];
theLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:23];
theLabel.backgroundColor = [UIColor clearColor];
// set the autoReiszing mask -- this way if the label spills over the editing
// [icon?] then the text will trail off in ...
theLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell.contentView addSubview:theLabel];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment