如何使用单点触控在 UITableView 中获取交替的行颜色?
我目前正在使用这个填充我的 TableView:
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;
}
最佳答案
添加这个类:
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;
}
}
}
在你的tableview中使用它:
var tvdelegate = new AlternatingTableViewDelegate()
myTableView .Delegate = tvdelegate
关于c# - UITableView 中的交替行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13701547/