xamarin.iOS垂直滚动图像

我正在尝试在Xamarin.iOS中构建一个UI,允许用户垂直滚动图像列表。 我不确定最好的方法是什么。 我已经看过使用UITableViewSource但是我不确定这是否是最好的方法。

我想要显示的数据不是真正的表格,它只是一个图像列表。 有没有办法模拟UITableViewSource只显示一个与屏幕一样宽的图像,允许用户向下滚动它们。

或者更好的方法是添加ScrollView并添加图像,允许用户向下滚动滚动视图?

任何建议或代码样本将不胜感激。

你可以使用UITableView来实现你需要的东西,这是一个例子。

首先,您可以调用示例代码,如下所示:

public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. List dataList = new List (); for (int i = 0; i < 20; i++) { //Make sure all images is already in the Resources folder dataList.Add ("test.png"); } UITableView myTalbeView = new UITableView (); myTalbeView.RowHeight = 80; myTalbeView.Frame = UIScreen.MainScreen.Bounds; myTalbeView.AllowsSelection = false;//If you don't want any image be selected, use it. myTalbeView.SeparatorStyle = UITableViewCellSeparatorStyle.None;//remove the under line myTalbeView.Source = new MyTableViewSource (dataList);//set source for tableView this.View.AddSubview (myTalbeView); } 

这是MyTableViewSource.cs:

 public class MyTableViewSource : UITableViewSource { private static string cellReuseID = "MyTalbeCell"; private List dataList; public MyTableViewSource(List _dataList) { this.dataList = _dataList; } public override nint RowsInSection (UITableView tableview, nint section) { return dataList.Count; } public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath) { MyTableCell cell = tableView.DequeueReusableCell (cellReuseID) as MyTableCell; if (null == cell) cell = new MyTableCell (UITableViewCellStyle.Default, cellReuseID); cell.ImageName = dataList [indexPath.Row]; return cell; } } 

这是MyTalbeCell.cs:

 public class MyTableCell : UITableViewCell { private UIImageView imageView; private string imageName = ""; public string ImageName{ get{ return imageName; } set{ imageName = value; imageView.Image = UIImage.FromFile (imageName); } } public MyTableCell (UITableViewCellStyle style,string reuseID) : base(style,reuseID) { imageView = new UIImageView (); this.AddSubview (imageView); } public override void LayoutSubviews () { imageView.Frame = this.Bounds; } } 

希望它可以帮到你。

如果您仍然需要帮助,请在此处留下问题,我会检查后者。