---
title: "Alternating row colors in UITableView"  
description: "Alternating row colors in UITableView"  
author: "Anonymous User"  
published: 2014-01-31  
updated: 2014-01-31  
canonical: https://www.mindstick.com/forum/1935/alternating-row-colors-in-uitableview  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Alternating row colors in UITableView

How do I get alternating [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) [colors](https://answers.mindstick.com/qa/31019/should-i-paint-my-interior-with-neutral-or-bright-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;        }
```

## Replies

### Reply by Pravesh Singh

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


---

Original Source: https://www.mindstick.com/forum/1935/alternating-row-colors-in-uitableview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
