Alternating row colors in UITableView

Total Post:108


 1896  View(s)
Rate this:

How do I get alternating row colors in a UITableView using monotouch?

I am currently populating my TableView using this:

public partial class myViewController : UITableViewController
        public static UINavigationController navigationController;
        public static IntPtr handle;
        public CompanyViewController (IntPtr handle) : base (handle)
        public override void ViewDidLoad ()
            base.ViewDidLoad ();
            Services service = new Services();
            var myList = service.GetList(param1);
            List<string> list = new List<string>();
            foreach(var c in myList)
                list.Add (c.Name);
            navigationController = NavigationController;
            handle = Handle;
            var source = new CompanyTableSource(list);
            myTableView.Source = source;
  1. Re: Alternating row colors in UITableView

    Hi John,

    Add this class:

    public class AlternatingTableViewDelegate :UITableViewDelegate
        public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
            if(indexPath.Row % 2 == 0) {
                cell.BackgroundColor = UIColor.White;
            } else {
                cell.BackgroundColor = UIColor.LightGray;

    Use it in you tableview:

    var tvdelegate = new AlternatingTableViewDelegate()

    myTableView .Delegate = tvdelegate

      Modified On Apr-04-2018 03:47:20 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.