【问题标题】:StyledStringElement Alternating Backgrounds in a UITableViewUITableView 中的 StyledStringElement 交替背景
【发布时间】:2013-06-21 20:24:42
【问题描述】:

我在 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;
        }
    }
}

【问题讨论】:

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


    【解决方案1】:

    我通过将以下帮助程序添加到我的 BaseDialogViewController 类中解决了这个问题,该类是 DialogViewController

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

    然后在我创建一个元素后的代码中,我将它传递给这个函数来设置样式。

    【讨论】:

      猜你喜欢
      • 2011-07-30
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 2011-10-13
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多