How to customize tableView separator in iPhone

前端 未结 12 2002
夕颜
夕颜 2020-11-28 20:49

By default there is a single line separator in uitableview.

But I want to put my customized line as a separator.

Is it possible? How?

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 21:43

    Tested on iOS 7 (GM):

    @implementation MyTableViewController
    
    - (void)viewDidLayoutSubviews {
        for (UIView *view in self.view.subviews) {
            if ([view isKindOfClass:NSClassFromString(@"_UITableViewCellSeparatorView")])
                view.backgroundColor = [UIColor redColor];
        }
    }
    
    @end
    

    NOTE: it appears the UITableView moves separators to the cells in some configurations, which would make this code not work unless you descend into all UITableViewCells as well.

提交回复
热议问题