How do I get the default cell separator color? Also, how do I set separator color per cell?

送分小仙女□ 提交于 2020-01-16 04:45:07

问题


I want to add a cell in the bottom that shows only if the app is loading more results when the user scrolls to the bottom of a tableview. I already did that. The problem is that it's a cell. So when I scroll down even further, the separator shows that it's just another cell in the table. I want to hide that. I have to change that cell's separator color, how do I do that to a particular cell? Also, Where/when do i do that?

I realize that if I change that cell's color (let's say it's #5), when I get the results and load them in, won't that also result in cell #5 still having an invisible separator? So how do I set it back to the default color? More particularly how do I get the default color for a tableviewcellseparator programmatically?

Thanks


回答1:


Here's a simple trick: you have to add en empty UIView inside your UITableView in Storyboard. The set the height = 0.

The last separator of the UITableView magically disappears.


Edit:

You will also need to edit your cellForRowAtIndexPath: like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];

    if (indexPath.row == [self tableView:tableView numberOfRowsInSection:[self numberOfSectionsInTableView:tableView]-1]-1) {
        //this is the last cell
        cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0);
    } else {
        cell.separatorInset = UIEdgeInsetsMake(0, 0, cell.bounds.size.width, 0);
    }
    return cell;
}



回答2:


Separator colour is a property of the table view, you can get or set it like so:

self.tableView.separatorColor = UIColor.blackColor()

But I don't think you cannot change the separator colours of a individual cell.

If you truly need that level of customization, you should probably just draw the separator bar yourself as, for example, a thin UIView at the top of the cell. Then you can change its appearance to whatever you want.



来源:https://stackoverflow.com/questions/37766614/how-do-i-get-the-default-cell-separator-color-also-how-do-i-set-separator-colo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!