soapbar soapbar - 5 months ago 20
iOS Question

The custom UITableViewCell can not set the selected background color

I have a subclass of UITableViewCell. It adds a few extra elements to the base view (via xib) ,

but It can not take effect.

enter image description here

cell.selectionStyle = UITableViewCellSelectionStyleBlue;


The above two kinds of Settings are unable to take effect.


cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.selectionStyle = UITableViewCellSelectionStyleGray;


Two other background style can take effect. I am very confused.

Answer

This is not an iOS mistake. There's no more blue selection style since iOS 7. The only selection styles provided are UITableViewCellSelectionStyleNone and UITableViewCellSelectionStyleGray.

From UITabieViewCell Class Reference:

UITableViewCellSelectionStyleBlue

The cell has a default background color when selected.

In iOS 7, the selection color is no longer blue. Use UITableViewCellSelectionStyleDefault instead.

Available in iOS 2.0 and later.

If you want, you can set your own custom selection background by setting the selectedBackgroundView property of UITableViewCell.

Comments