Skip to content

Instantly share code, notes, and snippets.

@romanr
Forked from pier-oliviert/UITableViewCell.m
Created June 27, 2012 10:07
Show Gist options
  • Save romanr/3003103 to your computer and use it in GitHub Desktop.
Save romanr/3003103 to your computer and use it in GitHub Desktop.
UITableViewCell subclass to handle indentationLevel
- (void)layoutSubviews {
[super layoutSubviews];
float indentPoints = self.indentationLevel * self.indentationWidth;
if (indentPoints > 0) {
[self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *view = (UIView *)obj;
CGFloat width = CGRectGetWidth(view.frame);
if (width > indentPoints * 2)
width -= indentPoints;
CGFloat x = CGRectGetMinX(view.frame);
if (x + indentPoints + width < CGRectGetMaxX(self.frame))
x += indentPoints;
view.frame = CGRectMake(
x,
CGRectGetMinY(view.frame),
width,
CGRectGetHeight(view.frame)
);
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment