更改MvvmCross对话框元素中的布局/框架

时间:2014-10-27 12:15:13

标签: mvvmcross monotouch.dialog

我试图通过继承Mvvmcross Dialog实现中的一些元素来轻松定制。

颜色和字体设置得很好,但是如果我尝试设置文本标签框架(在本例中为100 X ......)我就无法坚持下去。

有人能指出我在这里出错的方向吗?在几个不同的地方尝试过。

public class MyBooleanElement : BooleanElement {

    public MyBooleanElement (string caption) : base(caption, false)
    {

    }

    protected override UISwitch CreateSwitch()
    {
        UISwitch s = base.CreateSwitch();
        s.BackgroundColor = UIColor.Clear;
        s.Opaque = false;
        s.Layer.Opacity = 0.25f;
        return s;
    }

    protected override UITableViewCell GetCellImpl(UITableView tv)
    {
        var cell = base.GetCellImpl(tv);

        if (cell.BackgroundColor != UIColor.Clear) {
            cell.BackgroundColor = UIColor.Clear;
            cell.TextLabel.Font = Theme.GetContentFont();
            cell.TextLabel.TextColor = UIColor.White;

            cell.TextLabel.Frame =  new RectangleF(100, 0, 320, 20); // this is not holding, resets to 15
            cell.ContentView.Frame = new RectangleF(50, cell.ContentView.Frame.Top, cell.ContentView.Frame.Width, cell.ContentView.Frame.Height);  // try this also? 
        }

        return cell;
    }

    protected override void UpdateCaptionDisplay(UITableViewCell cell)
    {
        base.UpdateCaptionDisplay(cell);

        if (cell != null) {
            cell.TextLabel.Frame = new RectangleF(100, 0, 320, 20);  // this is not holding, resets to 15
            cell.TextLabel.BackgroundColor = UIColor.Blue;           // Yet this works? some constraints somewhere cannot see in source!
        }
    }
}

1 个答案:

答案 0 :(得分:0)

框架的对话框部分是为您定位标题(标签)和控件。

您应该稍微查看源代码,或者尝试了解它的工作原理。

您可以从断点开始并在调试时单步执行源代码。我确定你会看到15值的设定位置。

对不起,我无法给你一个确切的答案。我自己在iPad上对话元素的错误定位时遇到了一些问题,我不得不挖掘一下。

相关问题