Created
February 27, 2013 03:56
-
-
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
This file contains hidden or 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
| -(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