【问题标题】:Change Layout / Frames in MvvmCross Dialog Elements更改 MvvmCross 对话框元素中的布局/框架
【发布时间】:2014-10-27 12:15:12
【问题描述】:

我正在尝试通过继承 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!
        }
    }
}

【问题讨论】:

    标签: mvvmcross monotouch.dialog


    【解决方案1】:

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

    你应该看一下源代码,也许试着了解一下它是如何工作的。

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

    很抱歉,我不能给你一个准确的答案。我自己也遇到了一些问题,即 iPad 上对话框元素的位置不正确,我不得不深入研究一下。

    【讨论】:

    • 谢谢安德烈,我已经很好地查看了源代码,并且正如你所说的,下一步将不得不设置调试,正如你可以猜到的那样,希望有人之前已经打过这个。你在 PC 上使用 Visual Studio 进行调试还是 XS?
    猜你喜欢
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多