我如何设置RootElement的样式

时间:2013-02-02 16:45:36

标签: monotouch.dialog

我需要一种方式来设置Monotouch Dialogs RootElement的样式。我需要更改背景和字体颜色。

我已经创建了一个自定义RootElement,如下所示

public class ActivityRootElement : RootElement
{
    public ActivityRootElement (string caption) : base (caption)
    {

    }

    public ActivityRootElement(string caption, Func<RootElement, UIViewController> createOnSelected) : base (caption, createOnSelected)
    {
    }

    public ActivityRootElement(string caption, int section, int element) : base (caption, section, element)
    {
    }

    public ActivityRootElement(string caption, Group group) : base (caption, group)
    {
    }



    public override UITableViewCell GetCell (UITableView tv)
    {
        tv.BackgroundColor = Settings.RootBackgroundColour;
        return base.GetCell (tv);
    }

    protected override void PrepareDialogViewController(UIViewController dvc)
    {
        dvc.View.BackgroundColor =  Settings.RootBackgroundColour;
        base.PrepareDialogViewController(dvc);
    }

}

然后我调用自定义根元素,如下所示传入自定义DialogController

    section.Add (new ActivityRootElement(activity.Name, (RootElement e) => {
                return new ActivityHistoryDialogViewController (e,true);
            }));

未应用根元素样式。任何帮助都会被批准!!

2 个答案:

答案 0 :(得分:1)

如果您希望颜色是您在TableViewController中看到的唯一内容,则需要将BackgrounView设置为null。有一个视图超越应用样式,这将隐藏您正在寻找的颜色。

试试这个:

public override UITableViewCell GetCell (UITableView tv)
{
    tv.BackgroundColor = Settings.RootBackgroundColour;
    tv.BackgroundView = null;
    return base.GetCell (tv);
}

protected override void PrepareDialogViewController(UIViewController dvc)
{
    dvc.TableView.BackgroundColor =  Settings.RootBackgroundColour;
    dvc.TableView.BackgroundView = null;
    base.PrepareDialogViewController(dvc);
}

答案 1 :(得分:0)

为了使其工作,我必须覆盖MakeViewController方法并强制转换它通常返回到UITableViewController的UIViewController,然后进行编辑。

protected override UIViewController MakeViewController()
{
    var vc = (UITableViewController) base.MakeViewController();

    vc.TableView.BackgroundView = null;
    vc.View.BackgroundColor = UIColor.Red; //or whatever color you like
    return vc;
}