2016-07-22 1 views
-1

xamarin studio로 코드 만 있고 Storyboard 또는 디자이너가없는 iOS 앱을 C# 코드로 개발하고 있습니다.xamarin C# 스크롤하는 텍스트가있는 UIViewController

UIViewController보다 긴 텍스트가있는 UILabel (또는 UITextView)을 넣어야합니다. 는 예를 들어,이 긴 텍스트 내 UILabel의이다 :이 텍스트는 다음 더 이상 장치 화면이 될 것이다

string textrStr = ""; 
     var descStrLabel = new UITextView(new CGRect(0, 340, w, 1050)); 
     descStrLabel.BackgroundColor = UIColor.Black; 
     descStrLabel.Font = UIFont.SystemFontOfSize(10.0f); 
     descStrLabel.TextAlignment = UITextAlignment.Justified; 
     descStrLabel.TextColor = UIColor.LightGray; 
     textrStr += @"È universalmente riconosciuto che un lettore che osserva il layout di una pagina viene distratto dal contenuto testuale se questo è leggibile. Lo scopo dell’utilizzo del Lorem Ipsum è che offre una normale distribuzione delle lettere (al contrario di quanto avviene se si utilizzano brevi frasi ripetute, ad esempio “testo qui”), apparendo come un normale blocco di testo leggibile. Molti software di impaginazione e di web design utilizzano Lorem Ipsum come testo modello. Molte versioni del testo sono state prodotte negli anni, a volte casualmente, a volte di proposito (ad esempio inserendo passaggi ironici)."; 

     descStrLabel.Text = textrStr; 
     descStrLabel.TextContainer.LineBreakMode = UILineBreakMode.WordWrap; 
     descStrLabel.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; 

, 그래서 그것을 스크롤 할 필요가있다. 몇 가지 해결책을 시도했지만 아무 것도 작동하지 않습니다.

+0

무엇을 시도 했습니까? 첫 번째 권장 사항은 레이블을 UIScrollView에 삽입하는 것입니다. 사용 설명서는 https://developer.xamarin.com/recipes/ios/content_controls/scroll_view/use_a_scrollview/에 있습니다. – Bearcat9425

답변

1

UITextView, 1050에 대해 설정 한 높이가 문제입니다.이 값은 화면 높이보다 높으며 모든 텍스트를 저장할 수있을만큼 높으면 스크롤 할 필요가 없습니다. 그러나 화면보다 높기 때문에 대부분의 UITextView 자체가 화면에서 벗어나기 때문에 모든 텍스트를 볼 수 없습니다. 화면에서 텍스트보기를 차지할 높이의 높이를 설정하십시오.이 경우에는 screen (or view) height - 340으로 가정 할 것입니다. 340은 UITextView의 맨 위를 가졌기 때문에 높이가 아니라 전체를 잡고 있어야하기 때문입니다. 텍스트의 UITextView는 모든 텍스트를 저장할 수 없을 때만 스크롤 할 수 있습니다.

코드에서보기 컨트롤러의 기본보기에이 UITextView가 있는지 또는 하위보기에 있는지 여부를 확인할 수 없습니다.

var descStrLabel = new UITextView(new CGRect(0, 340, w, View.Bounds.Height - 340)); 

하위 뷰의 경우, 또한 containerView.Bounds.Height - 340

View.Bounds.Height - 340 교체는 가로 방향을 지원해야하는 경우, 나는 추가, FlexibleHeight 플래그 추천 할 것입니다 : 주요보기 경우, 시도

descStrLabel.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; 

해당 플래그가 없으면 가로로 회전 할 때 더 이상 UITextView의 높이가 화면에 표시 될 정도로 높지 않으므로 더 이상 아래로 스크롤 할 수 없습니다.

도움이 되었기를 바랍니다.