简体   繁体   中英

how to fit a long text into a UITextView or UILabel

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM