UITableViewCell setIndentationLevel
@property(nonatomic) NSInteger indentationLevel
Discussion of [UITableViewCell setIndentationLevel]
The default value of the property is zero (no indentation). The width for each level of indentation is determined by the indentationWidth property.
UITableViewCell setIndentationLevel example.
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (cell == nil)
{
cell = (UITableViewCell*)[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellType01"] autorelease];
[cell setIndentationLevel:indexPath.row];
[cell setIndentationWidth:10];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// Tag the view
[[[cell subviews] objectAtIndex:0] setTag:111];
UILabel* labelView = [[UILabel alloc] initWithFrame: CGRectMake(cell.indentationLevel*cell.indentationWidth, 0, 300, 20)];
}
}
{
if (cell == nil)
{
cell = (UITableViewCell*)[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellType01"] autorelease];
[cell setIndentationLevel:indexPath.row];
[cell setIndentationWidth:10];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// Tag the view
[[[cell subviews] objectAtIndex:0] setTag:111];
UILabel* labelView = [[UILabel alloc] initWithFrame: CGRectMake(cell.indentationLevel*cell.indentationWidth, 0, 300, 20)];
}
}
Example of [UITableViewCell setIndentationLevel].
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
customecell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[customecell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLbl.text=[[self.tabledata objectAtIndex:indexPath.row] valueForKey:@"name"];
cell.textLbl.font = [UIFont fontWithName:@"Helvetica" size:18];
[cell setIndentationLevel:[[[self.tabledata objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
cell.indentationWidth = 25;
float indentPoints = cell.indentationLevel * cell.indentationWidth;
cell.contentView.frame = CGRectMake(indentPoints,cell.contentView.frame.origin.y,cell.contentView.frame.size.width - indentPoints,cell.contentView.frame.size.height);
return cell;
}
static NSString *CellIdentifier = @"Cell";
customecell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[customecell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLbl.text=[[self.tabledata objectAtIndex:indexPath.row] valueForKey:@"name"];
cell.textLbl.font = [UIFont fontWithName:@"Helvetica" size:18];
[cell setIndentationLevel:[[[self.tabledata objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
cell.indentationWidth = 25;
float indentPoints = cell.indentationLevel * cell.indentationWidth;
cell.contentView.frame = CGRectMake(indentPoints,cell.contentView.frame.origin.y,cell.contentView.frame.size.width - indentPoints,cell.contentView.frame.size.height);
return cell;
}
UITableViewCell setIndentationLevel example.
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing
&& ((state & UITableViewCellStateShowingEditControlMask)
&& !(state & UITableViewCellStateShowingDeleteConfirmationMask)) ||
((state & UITableViewCellStateShowingEditControlMask)
&& (state & UITableViewCellStateShowingDeleteConfirmationMask)))
{
float indentPoints = self.indentationLevel * self.indentationWidth;
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width - indentPoints,
self.contentView.frame.size.height);
}
}
{
[super layoutSubviews];
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing
&& ((state & UITableViewCellStateShowingEditControlMask)
&& !(state & UITableViewCellStateShowingDeleteConfirmationMask)) ||
((state & UITableViewCellStateShowingEditControlMask)
&& (state & UITableViewCellStateShowingDeleteConfirmationMask)))
{
float indentPoints = self.indentationLevel * self.indentationWidth;
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width - indentPoints,
self.contentView.frame.size.height);
}
}