【问题标题】:Adding an image to a Section in Monotouch.Dialog将图像添加到 Monotouch.Dialog 中的部分
【发布时间】:2012-01-15 12:38:48
【问题描述】:

我使用 MonoTouch.Dialog 创建了一个包含几个部分的视图。这些部分需要在其他部分之前添加图像,但是我正在努力将 UIImage 添加到第一部分之前的区域。

我该怎么做呢?我已经突出显示了我希望图像在 RootElement 中的哪个位置。

public void HomeScreen ()
    {
        var root = CreateRoot_HomeScreen ();

        var dv = new DialogViewController (root, true);
        navigation.PushViewController (dv, true);
    }

    RootElement CreateRoot_HomeScreen()
    {
        // Set up the ImageView with the Logo in it
        var logo = UIImage.FromFile("Images/logo.png");

        var imageView = new UIImageView(logo);

        return new RootElement("iEngage"){
            // The Image should go here
            new Section(){

            },
            new Section("")
            {
                new StyledStringElement ("Search", delegate{ Console.Write("Clicked"); })
            }
        };
    }

【问题讨论】:

    标签: c# ios xamarin.ios monotouch.dialog


    【解决方案1】:

    这听起来像 MonoTouch 的 Sample 中的 页眉和页脚。基本上,您添加的每个 Section 都有您可以设置的 HeaderView 属性。

    您的UIImageView 可以分配给此属性,该属性将在该部分中插入您的徽标

    例如(从DemoHeaderFooters.cs复制/粘贴)

            var section = new Section () { 
                HeaderView = new UIImageView (UIImage.FromFile ("caltemplate.png")),
            };
    

    然后你在你的代码中使用这个部分:

       return new RootElement("iEngage"){
            section,
            new Section("")
            {
                new StyledStringElement ("Search", delegate{ Console.Write("Clicked"); })
            }
        };
    

    【讨论】:

    • 谢谢 poupou。我试过这个,我得到了一个扭曲的图像,它被拉伸/扭曲以适应一个部分的宽度和高度。我可以在其他地方指定这些宽度和高度吗?
    • poupou,我想出了如何通过设置 UIImageView 的 frame 属性来更改高度 - 谢谢。
    • 很高兴你得到它,不要犹豫编辑我的答案,如果你认为它会对人们有所帮助,请添加它!
    • Macropus - 你是如何摆脱 UIImageView 中的拉伸的?这对我不起作用... name.FooterView = new UIImageView(image) { Frame = new RectangleF(0, 0, 100, 100) };我仍然得到一张横跨整个表格宽度的图像(尽管高度已调整为我指定的高度)。
    • @OmriGazitt 看看这个Image Resizer for MonoTouch
    猜你喜欢
    • 1970-01-01
    • 2013-05-27
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多