StyledStringElement UITableView中的交替背景

时间:2013-06-21 20:24:42

标签: iphone uitableview xamarin.ios xamarin monotouch.dialog

我在Monotouch.Dialog UITableView中有一系列StyledStringElements。

我希望将每隔一行设置为具有不同的背景颜色(财务报告)。

是否有现成的方法可以执行此操作,如果没有,我可以覆盖什么来启用此功能?

在标准的UITableView中,我会为表创建一个新的委托:

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 = Settings.ColorAlternatingRow;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我通过将下面的帮助器添加到我的 BaseDialogViewController 类来解决这个问题,该类的子类是 DialogViewController

    internal int RowCount = 0;

    protected StyledStringElement Alternate(StyledStringElement element)
    {
        if (++RowCount % 2 == 0) element.BackgroundColor = Settings.ColorAlternatingRow;
        return element;
    }

然后在创建元素之后的代码中,我将它传递给此函数以进行样式化。

相关问题