private void Init() { Font = DefaultTitleFont.WithSize(DefaultTitleFont.PointSize); SubtitleFont = DefaultDetailFont.WithSize(DefaultDetailFont.PointSize); BackgroundColor = BgColor; TextColor = DefaultTitleColor; DetailColor = DefaultDetailColor; LineBreakMode = UILineBreakMode.TailTruncation; }
private void LBLareaM() { var rect = new CGRect(25, 210, 300, 175); _LBLarea = new UILabel(rect); UILineBreakMode NSLineBreakByWordWrapping = default(UILineBreakMode); _LBLarea.LineBreakMode = NSLineBreakByWordWrapping; _LBLarea.Lines = 10; _LBLarea.Text = $"where would you like to go:{Environment.NewLine} 0 = old house {Environment.NewLine} 1 = boat house {Environment.NewLine} 2 = mine {Environment.NewLine} 3 = forest {Environment.NewLine} 4 = field {Environment.NewLine} 5 = lake"; View.Add(_LBLarea); }
static SizeF SizeForString(string message, UIFont font, SizeF size, UILineBreakMode lineBreakMode) { /*if ([string respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) { * NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; * paragraphStyle.lineBreakMode = lineBreakMode; * NSDictionary *attributes = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle}; * CGRect boundingRect = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil]; * return CGSizeMake(ceilf(boundingRect.size.width), ceilf(boundingRect.size.height)); * } * * return [string sizeWithFont:font constrainedToSize:constrainedSize lineBreakMode:lineBreakMode];*/ return(TextUtils.SizeWithFont(message, font, size, lineBreakMode)); }
private void UpdateLineBreakMode() { UILineBreakMode lb = UILineBreakMode.Clip; if (this.TextTrimming == Controls.TextTrimming.WordEllipsis) { lb = UILineBreakMode.TailTruncation; } else if (this.NativeTextWrapping == Controls.TextWrapping.Wrap) { lb = UILineBreakMode.WordWrap; } (this.NativeUIElement as UILabel).LineBreakMode = lb; }
//===================================== labels================================== private void LblNt() { var rect = new CGRect(25, 60, 300, 130); _LblNarrater = new UILabel(rect); UILineBreakMode NSLineBreakByWordWrapping = default(UILineBreakMode); _LblNarrater.LineBreakMode = NSLineBreakByWordWrapping; _LblNarrater.Lines = 10; //_LblNarraterText.Layer.BorderWidth = 1f; //_LblNarraterText.Layer.BorderColor = UIColor.Black.CGColor; _LblNarrater.Text = $"you enter the mine and are attacked by a {EnermyName} using a {EnermyWeapon} "; View.Add(_LblNarrater); }
protected override void OnAttached() { try { _control = Control as UILabel; _defaultLineBreakMode = _control.LineBreakMode; _defaultLines = _control.Lines; _control.LineBreakMode = UILineBreakMode.TailTruncation; _control.Lines = 2; } catch (Exception ex) { Console.WriteLine($"Cannot set property on attached control. Error: {ex.Message}"); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Define needed objects NSString nsString = new NSString("Hello World!"); Selector selector = new Selector("sizeWithFont:forWidth:lineBreakMode:"); UIFont font = UIFont.FromName("Helvetica", 12); nfloat width = 200; UILineBreakMode mode = UILineBreakMode.WordWrap; // Invoke message CGSize size = cgsize_objc_msgSend_IntPtr_float_int( nsString.Handle, selector.Handle, font == null ? IntPtr.Zero : font.Handle, width, mode); // Report size Console.WriteLine("Size: {0}", size); }
public static CGSize DrawString (this NSString item, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) { // Get paragraph style var labelStyle = new NSMutableParagraphStyle(NSParagraphStyle.DefaultParagraphStyle.MutableCopy() as AppKit.NSMutableParagraphStyle); // Adjust alignment labelStyle.Alignment = alignment; // Adjust line break mode labelStyle.LineBreakMode = mode; // Define attributes var attributes = new NSStringAttributes () { Font = font.NSFont, ForegroundColor = UIStringDrawing.FillColor, ParagraphStyle = labelStyle }; // Preform drawing item.DrawInRect(rect, attributes); // Return new bounding size return new CGSize (rect.Width, rect.Height); }
public static SizeF GetStringSize(string text, UIFont font, SizeF size, UILineBreakMode lineBreakMode) { return sizeHelperView.StringSize(text, font, size, lineBreakMode); }
public static UILabel WithLineBreakMode(this UILabel self, UILineBreakMode lineBreakMode) { self.LineBreakMode = lineBreakMode; return(self); }
static extern CGSize cgsize_objc_msgSend_IntPtr_float_int( IntPtr target, IntPtr selector, IntPtr font, nfloat width, UILineBreakMode mode);
public static CGSize StringSize(this string This, UIFont font, CGSize constrainedToSize, UILineBreakMode lineBreakMode) { using (var self = ((NSString) This)) return self.StringSize (font, constrainedToSize, lineBreakMode); }
public static void SetUILineBreakMode(BindableObject element, UILineBreakMode value) => element.SetValue(UILineBreakModeProperty, value);
public static CGSize DrawString(this string This, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) { using (var self = ((NSString)This)) return(self.DrawString(rect, font, mode, alignment)); }
public static CGSize StringSize(this string This, UIFont font, CGSize constrainedToSize, UILineBreakMode lineBreakMode) { using (var self = ((NSString)This)) return(self.StringSize(font, constrainedToSize, lineBreakMode)); }
public static SizeF GetSize(this string _text, UIFont _font, SizeF?_bounds = null, UILineBreakMode _break = UILineBreakMode.WordWrap) { return(_text.ToNSString().StringSize(_font, _bounds ?? new SizeF(300, 411), _break)); }
public static CGSize DrawString(this string This, CGPoint point, global::System.nfloat width, UIFont font, UILineBreakMode breakMode) { using (var self = ((NSString) This)) return self.DrawString (point, width, font, breakMode); }
public static SizeF MeasureTextWithConstraint(CGContext context, string text, string fontName, float fontSize, UILineBreakMode breakMode, SizeF constraint) { NSString str = new NSString(text); SizeF size = str.StringSize(UIFont.FromName(fontName, fontSize), constraint, breakMode); return size; }
public static CGSize DrawString(this string This, CGPoint point, global::System.nfloat width, UIFont font, global::System.nfloat minFontSize, ref global::System.nfloat actualFontSize, UILineBreakMode breakMode, UIBaselineAdjustment adjustment) { using (var self = ((NSString) This)) return self.DrawString (point, width, font, minFontSize, ref actualFontSize, breakMode, adjustment); }
public static SizeF DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, CGColor fontColor, UILineBreakMode breakMode, UITextAlignment alignment) { context.SaveState(); context.SetFillColor(fontColor); NSString str = new NSString(text); SizeF size = str.DrawString(rect, UIFont.FromName(fontName, fontSize), breakMode, alignment); context.RestoreState(); return size; }
public static CGSize DrawString(this string This, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) { using (var self = ((NSString) This)) return self.DrawString (rect, font, mode, alignment); }
public static CGSize StringSize(this string This, UIFont font, global::System.nfloat minFontSize, ref global::System.nfloat actualFontSize, global::System.nfloat forWidth, UILineBreakMode lineBreakMode) { using (var self = ((NSString) This)) return self.StringSize (font, minFontSize, ref actualFontSize, forWidth, lineBreakMode); }
public static CGSize DrawString(this string This, CGPoint point, global::System.nfloat width, UIFont font, UILineBreakMode breakMode) { using (var self = ((NSString)This)) return(self.DrawString(point, width, font, breakMode)); }
static SizeF SizeForString (string message, UIFont font, SizeF size, UILineBreakMode lineBreakMode) { /*if ([string respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineBreakMode = lineBreakMode; NSDictionary *attributes = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle}; CGRect boundingRect = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil]; return CGSizeMake(ceilf(boundingRect.size.width), ceilf(boundingRect.size.height)); } return [string sizeWithFont:font constrainedToSize:constrainedSize lineBreakMode:lineBreakMode];*/ return TextUtils.SizeWithFont (message, font, size, lineBreakMode); }
public static CGSize DrawString(this string This, CGPoint point, global::System.nfloat width, UIFont font, global::System.nfloat minFontSize, ref global::System.nfloat actualFontSize, UILineBreakMode breakMode, UIBaselineAdjustment adjustment) { using (var self = ((NSString)This)) return(self.DrawString(point, width, font, minFontSize, ref actualFontSize, breakMode, adjustment)); }
protected CGSize calculateHeightOfTextForWidth(string text, UIFont font, float width, UILineBreakMode lineBreakMode) { return(text == null? new CGSize(0, 0) : UIKit.UIStringDrawing.StringSize(text, font, new CGSize(width, 300), lineBreakMode)); }
public static CGSize StringSize(this string This, UIFont font, global::System.nfloat forWidth, UILineBreakMode breakMode) { using (var self = ((NSString)This)) return(self.StringSize(font, forWidth, breakMode)); }
public static SizeF GetSize(this string _text, UIFont _font, SizeF? _bounds = null, UILineBreakMode _break = UILineBreakMode.WordWrap) { return _text.ToNSString().StringSize(_font, _bounds ?? new SizeF(300, 411), _break); }
public static CGSize StringSize(this string This, UIFont font, global::System.nfloat minFontSize, ref global::System.nfloat actualFontSize, global::System.nfloat forWidth, UILineBreakMode lineBreakMode) { using (var self = ((NSString)This)) return(self.StringSize(font, minFontSize, ref actualFontSize, forWidth, lineBreakMode)); }
public static CGSize StringSize(this string This, UIFont font, global::System.nfloat forWidth, UILineBreakMode breakMode) { using (var self = ((NSString) This)) return self.StringSize (font, forWidth, breakMode); }
public static CGSize DrawString(this NSString item, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) { // Get paragraph style var labelStyle = new NSMutableParagraphStyle(NSParagraphStyle.DefaultParagraphStyle.MutableCopy() as AppKit.NSMutableParagraphStyle); // Adjust alignment labelStyle.Alignment = alignment; // Adjust line break mode labelStyle.LineBreakMode = mode; // Define attributes var attributes = new NSStringAttributes() { Font = font.NSFont, ForegroundColor = UIStringDrawing.FillColor, ParagraphStyle = labelStyle }; // Preform drawing item.DrawInRect(rect, attributes); // Return new bounding size return(new CGSize(rect.Width, rect.Height)); }
/// <summary> /// Gets the size of the desired. /// </summary> /// <returns>The desired size.</returns> /// <param name="widthConstraint">Width constraint.</param> /// <param name="heightConstraint">Height constraint.</param> public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { if (widthConstraint < 0 || heightConstraint < 0) { return(new SizeRequest(Size.Zero)); } if (Control == null || Element == null) { return(new SizeRequest(Size.Zero)); } if (string.IsNullOrEmpty((ControlText ?? ControlAttributedText?.ToString()))) { return(new SizeRequest(Size.Zero)); } UpdateFont(); //if (Invalid || Math.Abs(widthConstraint - LastWidthConstraint) > 0.01 || Math.Abs(heightConstraint - LastHeightContraint) > 0.01 || Math.Abs(Element.MinFontSize - LastMinFontSize) > 0.01) { LastWidthConstraint = widthConstraint; LastHeightContraint = heightConstraint; LastMinFontSize = Element.MinFontSize; switch (Element.LineBreakMode) { case LineBreakMode.HeadTruncation: ControlLineBreakMode = UILineBreakMode.HeadTruncation; break; case LineBreakMode.TailTruncation: ControlLineBreakMode = UILineBreakMode.TailTruncation; break; case LineBreakMode.MiddleTruncation: ControlLineBreakMode = UILineBreakMode.MiddleTruncation; break; case LineBreakMode.NoWrap: ControlLineBreakMode = UILineBreakMode.Clip; ControlLines = 1; break; case LineBreakMode.CharacterWrap: ControlLineBreakMode = UILineBreakMode.CharacterWrap; break; case LineBreakMode.WordWrap: default: ControlLineBreakMode = UILineBreakMode.WordWrap; break; } var tmpFontSize = (nfloat)Element.FontSize; if (tmpFontSize < 0) { tmpFontSize = (nfloat)(UIFont.LabelFontSize * Math.Abs(tmpFontSize)); } if (Math.Abs(tmpFontSize) <= double.Epsilon * 10) { tmpFontSize = UIFont.LabelFontSize; } var minFontSize = (nfloat)LastMinFontSize; if (minFontSize < 0) { minFontSize = 4; } if (tmpFontSize < minFontSize) { tmpFontSize = minFontSize; } ControlLines = int.MaxValue; double linesHeight = -1; double desiredWidth = widthConstraint; if (Element.Lines == 0) { if (!double.IsInfinity(heightConstraint)) { ControlLines = 0; tmpFontSize = ZeroLinesFit(widthConstraint, heightConstraint, tmpFontSize); } } else { if (Element.AutoFit == AutoFit.Lines) { if (double.IsPositiveInfinity(heightConstraint)) { linesHeight = Element.Lines * (ControlFont.LineHeight + ControlFont.Leading); } else { var lineHeightRatio = ControlFont.LineHeight / ControlFont.PointSize; var leadingRatio = ControlFont.Leading / ControlFont.PointSize; //tmpFontSize = (nfloat)(((heightConstraint) / ((1 + leadingRatio) * Element.Lines)) / lineHeightRatio - 0.1f); var tmpLineSize = (nfloat)(heightConstraint - 0.05f) / Element.Lines; tmpFontSize = tmpLineSize / lineHeightRatio; } } else if (Element.AutoFit == AutoFit.Width) { tmpFontSize = WidthFit(widthConstraint, tmpFontSize); } } if (tmpFontSize < minFontSize) { tmpFontSize = minFontSize; } if (Math.Abs(tmpFontSize - Element.FittedFontSize) > 0.05) { //Device.StartTimer(TimeSpan.FromMilliseconds(50), () => //{ if (Element != null && Control != null) // multipicker test was getting here with Element and Control both null { #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator Element.FittedFontSize = tmpFontSize == Element.FontSize || (Element.FontSize == -1 && tmpFontSize == UIFont.LabelFontSize) ? -1 : (double)tmpFontSize; #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator Debug("SETTING FITTED FONT SIZE: " + Element?.FittedFontSize); } //return false; //}); } var syncFontSize = (nfloat)((ILabel)Element).SynchronizedFontSize; if (syncFontSize >= 0 && tmpFontSize != syncFontSize) { tmpFontSize = syncFontSize; } ControlFont = ControlFont.WithSize(tmpFontSize); CGSize cgSize = LabelSize(widthConstraint, tmpFontSize); Debug("cgSize: " + cgSize); //if (Control.Font != ControlFont || Control.AttributedText != ControlAttributedText || Control.Text != ControlText || Control.LineBreakMode != ControlLineBreakMode || Control.Lines != ControlLines) { Control.Hidden = true; Control.Lines = Element.Lines; Control.LineBreakMode = ControlLineBreakMode; Control.AdjustsFontSizeToFitWidth = false; Control.ClearsContextBeforeDrawing = true; Control.ContentMode = UIViewContentMode.Redraw; Control.Font = ControlFont; if (ControlAttributedText != null) { Control.AttributedText = ControlAttributedText; } else { Control.Text = ControlText; } Control.Hidden = false; } double reqWidth = cgSize.Width; double reqHeight = cgSize.Height + 0.05; var textHeight = cgSize.Height; var textLines = Lines(textHeight, Control.Font); string alg = "--"; //string cnstLinesStr = "CL: n/a "; //string lineHeight = "LH: " + Control.Font.LineHeight.ToString("00.000"); //string cnstLinesHeight = "CLH: n/a "; if (double.IsPositiveInfinity(heightConstraint)) { Debug("A"); if (Element.Lines > 0) { if (Element.AutoFit == AutoFit.Lines)// && Element.Lines <= textLines) { reqHeight = Element.Lines * Control.Font.LineHeight; } else if (Element.AutoFit == AutoFit.None && Element.Lines <= textLines) { reqHeight = Element.Lines * Control.Font.LineHeight; } } // alg = "∞A"; //} Control.Center = new CGPoint(Control.Center.X, reqHeight / 2); Debug("Control.Center: " + Control.Center); } else { Debug("B"); var constraintLines = Lines(heightConstraint, Control.Font); Debug("\t constraintLines: " + constraintLines); var constraintLinesHeight = Math.Floor(constraintLines) * Control.Font.LineHeight; Debug("\t constraintLinesHeight: " + constraintLinesHeight); //cnstLinesStr = "CL: " + constraintLines.ToString("0.000"); if (Element.Lines > 0 && Element.Lines <= Math.Min(textLines, constraintLines)) { reqHeight = Element.Lines * Control.Font.LineHeight; alg = "A"; } else if (textLines <= constraintLines) { reqHeight = textHeight; alg = "B"; } else if (constraintLines >= 1) { reqHeight = constraintLinesHeight; alg = "C"; } else { reqHeight = heightConstraint; alg = "D"; } Debug("\t alg: " + alg); Debug("\t reqHeight: " + reqHeight); Debug("\t Element.VerticalTextAlignment: " + Element.VerticalTextAlignment); if (Element.VerticalTextAlignment == TextAlignment.Start) { Control.Center = new CGPoint(Control.Center.X, reqHeight / 2); } else if (Element.VerticalTextAlignment == TextAlignment.End) { Control.Center = new CGPoint(Control.Center.X, heightConstraint - reqHeight / 2); } Debug("Control.Center: " + Control.Center); } LastDesiredSize = new SizeRequest(new Size(reqWidth, reqHeight), new Size(10, ControlFont.LineHeight)); } return(LastDesiredSize); }
protected SizeF calculateHeightOfTextForWidth(string text, UIFont font, float width, UILineBreakMode lineBreakMode){ return text==null? new SizeF(0, 0) : this.StringSize(text, font, new SizeF(width, 300), lineBreakMode); }
public CCLabelTTF(string label, SizeF dimensions, UITextAlignment alignment, UILineBreakMode lineBreakMode, string fontName, float fontSize) : this(label, fontName, fontSize, dimensions, alignment, lineBreakMode) { }
protected SizeF calculateHeightOfTextForWidth(string text, UIFont font, float width, UILineBreakMode lineBreakMode) { return(text == null? new SizeF(0, 0) : this.StringSize(text, font, new SizeF(width, 300), lineBreakMode)); }
public static CGSize DrawString(this string This, CGPoint point, nfloat width, UIFont font, nfloat fontSize, UILineBreakMode breakMode, UIBaselineAdjustment adjustment) { using (var self = ((NSString)This)) return(self.DrawString(point, width, font, fontSize, breakMode, adjustment)); }