I'm have a number rows I'm inserting into a table using -insertRowsAtIndexPaths:withRowAnimation, and I would like the rows to be indented from the left to distinguish them from the rest of the cells. The indentationLevel property of UITableViewCell looks like it's exactly what I need, but it doesn't seem to do anything. Here's the code I'm using to set the indentation level (dot syntax doesn't make a difference):
[cell setIndentationWidth:10];
[cell setIndentationLevel:1];
Is indentationLevel what I want, or should I be looking elsewhere?
indentationLevel and indentationWidth affect the positioning of the standard items textLabel, detailTextLabel, and imageView. They do not affect the origin of contentView's frame.
If you are not using textLabel, etc. (perhaps because targeting iPhone OS 2), you need to handle the indentation manually, as the previous answer shows.
This appears to be a bug in iOS 7 if you are not using custom cells.
Setting either indentationLevel
or indentationWidth
within tableView:cellForRowAtIndexPath:
has no effect on the cell's layout when it is time to display it.
For example, consider the following code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
BOOL isIndented = indexPath.row % 2;
cell.textLabel.text = isIndented ? @"Indented" : @"Not indented";
cell.indentationLevel = isIndented;
}
I don't have enough reputation to post screenshots, but the result is different between iOS 6 and iOS 7. This is using Xcode 5 and the iOS 7 SDK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With