Reputation: 1700
i'm developing an ios app with xamarin. i need to fit a long text into a content (UILabel or UITextView). this is the code i used:
var descStrLabel = new UITextView(new CGRect(0, 250, w, 550));
descStrLabel.BackgroundColor = UIColor.Black;
descStrLabel.Font = UIFont.SystemFontOfSize(10.0f);
descStrLabel.TextAlignment = UITextAlignment.Center;
descStrLabel.TextColor = UIColor.LightGray;
descStrLabel.Text = @"HERE THE LONG TEXT...";
//descStrLabel.Lines = 0;
descStrLabel.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
View.Add(unified);
View.Add(subtitle);
View.Add(descStrLabel);
When i debug the application, the last part of the text is missing...
maybe i need to set the width at runtime...
thanks in advance for your help
Upvotes: 0
Views: 1215
Reputation: 271945
I don't really know how you want to "fit" the text. If you want to show the text all in one line, try calling SizeToFit()
:
desc.SizeToFit();
documentation for SizeToFit()
:
Moves and resizes the UIView so that it tightly encloses its UIView.Subviews
If you want the UITextView
to wrap lines, then you don't need to do anything! Line wrapping is enabled by default. If it doesn't for you, try setting LineBreakMode
:
desc.TextContainer.LineBreakMode = UILineBreakMode.WordWrap;
documentation for WordWrap
:
Wraps at the first word that does not fit.
Upvotes: 2