Search code examples
iosxamarincolorsxamarin.ioscell

How can I change the cell color inside GetCell()?


I'm using the Xamarin.SideMenu NuGet Package. https://github.com/TheEightBot/Xamarin.SideMenu

Everything works fine, except that I need to make a few customizations. Mainly I need to change the font color of the flyout drawer menu options.

I've tried setting cell.TintColor = UIColor.Red;, but it didn't do anything.

Here is my code:

   public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        var cell = tableView.DequeueReusableCell(“VibrantCell”);
        cell.TextLabel.Text = “Index ” + indexPath.Row;
       cell.TintColor = UIColor.Blue;
       cell.BackgroundColor = UIColor.Green;
        return cell;
    }

   [Export(“tableView:willDisplayCell:forRowAtIndexPath:“)]
   public override void WillDisplay(UITableView tableView, UITableViewCell cell, Foundation.NSIndexPath indexPath)
   {
       cell.TintColor = UIColor.Red; // no effect?
       cell.BackgroundColor = UIColor.Green; // no effect?
   }

For some reason the color is not changing and is still black.

Is there a way I can get a flyoutdrawer on native Xamarin.iOS where the text color is something other than black?

Thank you very much.


Solution

  • You should not be modifying the cell itself. You should be modifying the cell's TextLabel property.

    So it should be:

    cell.TextLabel.TextColor = UIColor.Red;