Thomas Bandt

Über mich | Kontakt | Archiv

Größe von normalen Strings ermitteln [Xamarin.iOS]

label.StringSize(cleanMessage, label.Font, new SizeF(210, float.MaxValue), UILineBreakMode.WordWrap);

label ist ein UILabel, 210 die gewünschte fixe (und maximale) Breite. Das Ergebnis gibt die errechnete Höhe zurück.

Kommentare

  1. Thomas schrieb am Samstag, 16. August 2014 17:40:00 Uhr:

    Funktioniert ab iOS7 nicht mehr, dafür aber das hier:

    public static float GetHeight(this string text, float width, UIFont font)
    {
    using (var nsText = new NSString(text))
    {
    var attributes = new UIStringAttributes
    {
    Font = font
    };

    RectangleF size = nsText.GetBoundingRect(
    new SizeF(width, float.MaxValue),
    NSStringDrawingOptions.UsesLineFragmentOrigin,
    attributes,
    null
    );

    return size.Height;
    }
    }


« Zurück  |  Weiter »