I have created a custom UITableViewCell
. The table view is showing data fine. What I am stuck in is when user touches cell of tableview, then I want to show the background color of the cell other than the default [blue color] values for highlighting the selection of cell. I use this code but nothing happens:
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
Select the Tableview. Go to the Attributes Inspector. Set the Tableview Background Colour. Set the View Background Colour.
Inside the cellForRowAt indexPath method, on the table view cell, set the selectionStyle to . none .
No need for custom cells. If you only want to change the selected color of the cell, you can do this:
Objective-C:
UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor redColor]; [cell setSelectedBackgroundView:bgColorView];
Swift:
let bgColorView = UIView() bgColorView.backgroundColor = UIColor.red cell.selectedBackgroundView = bgColorView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With