Change the selected cell background colour using UIAppearance

前端 未结 3 1462
梦谈多话
梦谈多话 2020-12-20 07:43

I need to change the selected cell background colour for all the cells in my app. As I know there is a way to use UIAppearance protocol for this purposes. Is it

3条回答
  •  北海茫月
    2020-12-20 08:20

    You can't do this direct to UITableViewCell, but you can do it for its contentView:

    [[UIView appearanceWhenContainedIn:[UITableViewCell class], nil] setBackgroundColor:[UIColor redColor]];
    

    Note that it will change all the subViews bg color.

    Another option is writing a category or subclass the UITableViewCell with UI_APPEARANCE_SELECTOR mark, check this question:

    iOS: Using UIAppearance to define custom UITableViewCell color

提交回复
热议问题