2016-08-10 10 views
0

Xamarin.iOSでユーザーが画像のリストを垂直方向にスクロールできるUIを構築しようとしています。私は最良のアプローチが何であるかは分かりません。私はUITableViewSourceを使用して見てきましたが、これが最善の方法であるかどうかはわかりません。xamarin.iOS画像を垂直方向にスクロールする

私が表示したいデータは実際には表形式ではなく、単なる画像の一覧です。 UITableViewSourceをモールドして画面と同じ幅の画像を表示する方法はありますか?ユーザーが画面をスクロールできるようにします。

また、ScrollViewを追加して、スクロールビューをスクロールダウンするだけの画像を追加する方が良いでしょうか?

すべてのアドバイスやコードサンプルをいただければ幸いです。

答えて

1

あなたは必要なものを実装するためにUITableViewを使用できますが、これはサンプルです。

最初の仕上げで、あなたはこのようなサンプルコードを呼び出すことができます。

public override void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 
     // Perform any additional setup after loading the view, typically from a nib. 

     List<string> dataList = new List<string>(); 
     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<string> dataList; 

    public MyTableViewSource(List<string> _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; 
    } 
} 

それがあなたを助けることを願っています。

まだ何か助けが必要な場合は、ここで質問を残して、私は後者をチェックします。

+0

これは、あなたが私の質問の1つに優れた解決策を提供した2回目の時です。優れたコード例を使って、明確かつ簡潔な答え。私はあなたが仕事が大好きです、ありがとうございます –

+0

あなたは歓迎です、あなたはXamarinで開発を楽しんで願っています。 –

関連する問題