Change the UITableView separatorColor for a single UITableViewCell

前端 未结 3 1267
醉梦人生
醉梦人生 2021-01-02 03:17

I have a UITableView that uses a variety of custom UITableViewCells.

I\'d like to be able to have one of these table cells appear with a di

3条回答
  •  萌比男神i
    2021-01-02 03:59

    Starting from iOS 7 something like this seems to be working fine:

    1. Set UITableViewCellSeparatorStyleSingleLine on your UITableView
    2. For the cell that you want to change the separator color first hide the separator by changing the insets cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 10000);
    3. Change the background color of the cell that should have different separator color cell.backgroundColor = [UIColor greenColor];

    Now separator will have the same color as your cell's backgroundcolor. Note that all this can be set on your cell's xib file without any code. Also note that you probably want to change cell's contentView's background color to something different than default (probably white) so green color will appear only on the separator line.

提交回复
热议问题