UIView backgroundColor disappears when UITableViewCell is selected

前端 未结 17 1033
谎友^
谎友^ 2020-11-30 17:49

I have a simple tableViewCell build in interface builder. It contains a UIView which contains an image. Now, when I select the cell, the default blue selection background is

17条回答
  •  粉色の甜心
    2020-11-30 18:37

    Brooks has a great explanation for why this happens, but I think I have a better solution.

    In your subview, override setBackgroundColor: to what ever color you want. The setter will still be called, but only your color specified will be enforced.

    - (void)setBackgroundColor:(UIColor *)backgroundColor {
        [super setBackgroundColor:[UIColor whiteColor]];
    }
    

提交回复
热议问题