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;
}
Wouldn't it just make more sense to make the UITableViewCell taller than the content to begin with? If you're content is always 100px high , just make the cell 110px to get that extra 10px space you need, No custom cell needed :)
To set the left margin you can use:
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath: (NSIndexPath *)indexPath
{
return 1;
}
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