How to define a margin for uitableviewcell

advertisements

How to set the margin of UITableViewCell programmatically without creating a whole new custom cell ?


You need to subclass UITableViewCell and override layoutSubviews method:

- (void)layoutSubviews {
    [super layoutSubviews];
    CGRect tmpFrame = self.imageView.frame;
    tmpFrame.origin.x += 10;
    self.imageView.frame = tmpFrame;

    tmpFrame = self.textLabel.frame;
    tmpFrame.origin.x += 10;
    self.textLabel.frame = tmpFrame;

    tmpFrame = self.detailTextLabel.frame;
    tmpFrame.origin.x += 10;
    self.detailTextLabel.frame = tmpFrame;
}