iPhone - inserting space between custom table cells in UITableView
I have a UITableView with custom cells in it. I'd like to add a little red bar between the ce开发者_运维问答lls to have the cells be more distinct.
Is there an easy way to do this?
Thanks!
Use the separatorStyle
and separatorColor
properties of the UITableView
. For example:
- (void) viewDidLoad
{
self.tableView.separatorColor = [UIColor redColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
That style is the default, there are some others, but depending on what OS you are targeting (the etched style is only available as of 3.2, for example).
Apple's docs on the UITableView
1- Override
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
If indexPath.row % 2 == 1 (odd indexpath row), remove the text on your cell, set red as background color and return that cell. If you are populating your table using an array, you have to take that extra red cells into account and populate accordingly.
2 - Write a custom UITableView cell with some extra red space on the bottom, and return that cel on cellForRowAtIndexPath. Remove the red space on the bottom cell if necessary.
精彩评论