2016-08-10 6 views
0

Xamarin.iOS에서 사용자가 이미지 목록을 수직 스크롤 할 수있는 UI를 만들려고합니다. 나는 최선의 접근 방법이 무엇인지 확신 할 수 없다. UITableViewSource 사용하여 보았다 그러나 최선의 방법이 될지 잘 모르겠습니다.xamarin.iOS 이미지를 수직 스크롤

표시하려는 데이터는 실제로는 표 형식이 아니며 이미지 목록 일뿐입니다. UITableViewSource를 몰드하여 화면만큼 넓은 이미지를 보여줄 수 있습니까? 사용자가 스크롤 할 수 있습니다.

또는 더 나은 방법은 ScrollView를 추가하고 사용자가 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

내 질문에 훌륭한 솔루션을 제공 한 것은 이번이 두 번째입니다. 우수 코드 예제로 명확하고 간결한 대답. 나는 일하는 것을 좋아한다. 고맙다. –

+0

당신은 Xamarin으로 발전하는 것을 즐긴다. –