2012-11-29 2 views

답변

1

이 코드는 기본 이미지 뷰 프레임 설정 (크기 및 x 위치)이 있다고 가정합니다. 동일한보기 간격으로보기에 세로로보기 모음을 세로로 배치합니다. 컬렉션에 이미지가 하나 뿐인 경우에도 중앙에 위치합니다.

UIImageView img1, img2; 
     List<UIView> subViews; 

     if (img1 != null) 
     { 
      subViews.Add(img1); 
     } 


     if (img2 != null) 
     { 
      subViews.Add(img2); 
     } 

     float totalHeight = 0; 

     foreach (UIView subView in views) 
     { 
      totalHeight += subView.Frame.Height;     
     } 

     float spacing = (this.Bounds.Height - totalHeight)/(subView.Length +1) ; 
     float currentY = 0; 

     foreach (UIView subView in subViews) 
     { 
      currentY += spacing; 

      if (subView.Superview == null) 
      { 
       this.Add (subView); 
      } 

      subView.Frame = new RectangleF(subView.Frame.X,currentY,subView.Frame.Width, subView.Frame.Height); 

      currentY += subView.Frame.Height; 

     } 
관련 문제