Ios MvxCollectionViewCell的显示背景

Ios MvxCollectionViewCell的显示背景,ios,xamarin,mvvmcross,Ios,Xamarin,Mvvmcross,我试图在用Xamarin和MvvmCross构建的iPhone应用程序中显示MvxCollectionViewCell的背景图像。我的目标是iOS 6.0及以上版本。下面是我正在使用的代码。我在显示背景图像时遇到了一些问题。我似乎不知道我做错了什么。看起来应该是相当直截了当的。我在XCode中创建了这个单元格。电池是100 X 100。它包含一个90 X 72的UIImageView。UIImageView的X和Y分别为5和8。我也很难在单元格内调整图像的大小,但我计划在不久的将来发布另一个问题

我试图在用Xamarin和MvvmCross构建的iPhone应用程序中显示MvxCollectionViewCell的背景图像。我的目标是iOS 6.0及以上版本。下面是我正在使用的代码。我在显示背景图像时遇到了一些问题。我似乎不知道我做错了什么。看起来应该是相当直截了当的。我在XCode中创建了这个单元格。电池是100 X 100。它包含一个90 X 72的UIImageView。UIImageView的X和Y分别为5和8。我也很难在单元格内调整图像的大小,但我计划在不久的将来发布另一个问题

using MonoTouch.UIKit;
using Cirrious.MvvmCross.Binding.Touch.Views;
using Cirrious.MvvmCross.Binding.BindingContext;

namespace DriveThroughSafari.Touch.Views.Pictures
{
public sealed partial class AnimalCutoutCell : MvxCollectionViewCell
{
    public static readonly UINib Nib = UINib.FromName ("AnimalCutoutCell", NSBundle.MainBundle);
    public static readonly NSString Key = new NSString ("AnimalCutoutCell");

    private readonly MvxImageViewLoader _loader;

    public AnimalCutoutCell (IntPtr handle) : base (handle)
    {

        MainImage = new UIImageView();
        _loader = new MvxImageViewLoader(() => MainImage);

        BackgroundView = new UIImageView {Image = new UIImage("Images/photo-frame")};

        this.DelayBind(() =>
            {
                var set = this.CreateBindingSet<AnimalCutoutCell, AnimalDataViewModel>();
                set.Bind(_loader).To(animal => animal.ImageUrl);
                set.Apply();
            });
    }

    public static AnimalCutoutCell Create ()
    {
        return (AnimalCutoutCell)Nib.Instantiate (null, null) [0];
    }
  }
 }
使用MonoTouch.UIKit;
使用cirries.MvvmCross.Binding.Touch.Views;
使用cirries.MvvmCross.Binding.BindingContext;
命名空间驱动通过safari.Touch.Views.Pictures
{
公共密封部分类AnimalCutoutCell:MvxCollectionViewCell
{
公共静态只读UINib Nib=UINib.FromName(“AnimalCutoutCell”,NSBundle.MainBundle);
public static readonly NSString Key=new NSString(“AnimalCutoutCell”);
私有只读MvxImageViewLoader\u loader;
公共AnimalCutoutCell(IntPtr句柄):基础(句柄)
{
MainImage=新的UIImageView();
_加载器=新的MvxImageViewLoader(()=>MainImage);
BackgroundView=新UIImageView{Image=新UIImage(“图像/相框”)};
这个.DelayBind(()=>
{
var set=this.CreateBindingSet();
set.Bind(_loader).To(animal=>animal.ImageUrl);
set.Apply();
});
}
公共静态AnimalCutoutCell创建()
{
return(AnimalCutoutCell)Nib.Instantiate(null,null)[0];
}
}
}

我感谢你的帮助

我尝试在以下位置修改样本:

我更改了代码以匹配您的-在构造函数中包括这一行:

BackgroundView = new UIImageView {Image = new UIImage("MyImage.png")};
其中图像
MyImage.png
包含在Touch项目根目录中的构建操作
内容中

这很有效



我怀疑这里的第一步是编写一些测试代码并使用调试器-var myImage=UIImage.FromFile(“Images/photoframe”)
返回什么?它是有效的UIImage吗?

可能是当nib加载时,您的背景会被覆盖-您可以使用覆盖-类似于加载nib时的覆盖。没有像往常一样在moStuart正常在线,我很感谢您的反馈!!事实证明,我的图像比UIImageView大很多,它没有调整大小以适应视图,而是占据了整个单元格。创建具有正确尺寸的图像解决了该问题。有没有关于自动调整图像大小以适应UIImageView的想法?正如你在上面看到的,我正在使用MvxImageViewLoader加载数据。这类问题的新问题真的(有助于搜索)-但是我想你会像我一样容易找到答案,如果你。。。搜索
UIImageView
scale
-我相信您会找到答案。。。