0

I need to change the highlight of IOS list view to red color. As of now, I followed forums and was able to set the cell.SelectionStyle to none. And the highlight does not appear when i select on a Tab. But as my final goal is still to obtain a red highlight? Any ideas how I can achieve this?

I have read forums and they said that I should subclass the UITableViewCell class in this thread How do I set UITableViewCellSelectionStyle property to some custom color? and so I tried

public void CustomUITableViewCell:UITableViewCell
{
   public override virtual void SetHighlighted(bool highlighted, bool animated)
  {
  }

}

But the issue is when I tried, self does not have a background color property for me to set so what should I do now?

Little Kid
  • 55
  • 10

1 Answers1

0

I just convert the Objective-C to C#.

Create CustomRenderer of ViewCell , set SelectedBackgroundView to Cell, the whole code as below.

[assembly: ExportRenderer(typeof(ViewCell), typeof(MyViewCellRenderer))]
namespace ProjectName.iOS
{
    public class MyViewCellRenderer : ViewCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var cell = base.GetCell(item, reusableCell, tv);

            cell.SelectedBackgroundView = new UIView(cell.Bounds);
            cell.SelectedBackgroundView.BackgroundColor = UIColor.Red;

            return cell;     
        }
    }
}
ColeX
  • 14,062
  • 5
  • 43
  • 240