i want some left space, 10 pixels, to UITablViewcCell
. I write code below but its scrolling content horizontally. I dont want that.
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 130.0, 768.0)];
self.horizontalTableView.contentInset = UIEdgeInsetsMake(0.0, 10.0, 0.0, 0.0);
Do i need to use contentOffset
contentSize
property of tableview.
I think the best solution is to create subclass UITableViewCell and set the frames of its subiews in layoutSubviews
method to suit your spacing requirements. This will be lot cleaner and extendible. A closer look at tableview cells is a good read for this.
But there are some short-cuts towards this as well, each with its own disadvantages:
Set indentation for cells
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
This method will add indentation to your cell contents (left margins). But the cell separator will occupy the actual width of the cell, i.e the table width. So you'll need to set the separator style to none, so that it is won't be shown. But not applicable if you need a cell separator.
Reduce the entire tableViews frame size
This is the easiest way and quite obvious, but its lame when you require a margin between cell and the tableView.
As you have done it, setting contentInset, you should have noticed the discussion about it in Docs.
Use this property to add to the scrolling area around the content. The unit of size is points. The default value is UIEdgeInsetsZero.
I thought playing with contentOffset and contentSize would help achieve margins, but for me changing the values never had any effect. Probably as Andrey said, they might be managed internally. But I would love to hear more about these properties and their reflected behaviors.
EDIT
contentOffset and contentSize are inherited from UIScrollView and means same in UITableView as it a subclass of UIScrollView.
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