public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound) { base.Apply(stylesheet, styleBound, maxBound); StyleHelper style = stylesheet.GetHelper <StyleHelper> (); _view.Text = _text; // background color, borders style.SetBackgroundSettings(this); // text-format _textFormat = style.TextFormat(this); // font UIFont f = style.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } switch (_textFormat) { case TextFormat.Format.Text: _view.Text = _text; // text color _view.TextColor = _textColor = style.ColorOrClear <BitMobile.Controls.StyleSheet.Color> (this); // selected-color _selectedColor = style.Color <SelectedColor> (this); break; case TextFormat.Format.Html: string span = string.Format("<span style=\"font-family: {0}; font-size: {1:F0}; color: {2}\">{3}</span>", _view.Font.FamilyName, _view.Font.PointSize, "{0}", "{1}"); // text color _textHtmlSpan = string.Format(span, style.ColorString <BitMobile.Controls.StyleSheet.Color> (this), "{0}"); // selected-color string selectedColor = style.ColorString <SelectedColor> (this); if (selectedColor != null) { _selectedHtmlSpan = string.Format(span, selectedColor, "{0}"); } SetSpannedText(_textHtmlSpan); break; default: throw new NotImplementedException("Text format not found: " + _textFormat); } // word wrap bool nowrap = style.WhiteSpaceKind(this) == WhiteSpace.Kind.Nowrap; if (!nowrap) { _view.TextContainer.LineBreakMode = UILineBreakMode.WordWrap; _view.TextContainer.MaximumNumberOfLines = 0; } else { _view.TextContainer.LineBreakMode = UILineBreakMode.TailTruncation; _view.TextContainer.MaximumNumberOfLines = 1; } // text align switch (style.TextAlign(this)) { case TextAlign.Align.Left: _view.TextAlignment = UITextAlignment.Left; break; case TextAlign.Align.Center: _view.TextAlignment = UITextAlignment.Center; break; case TextAlign.Align.Right: if (nowrap) { _view.TextContainer.LineBreakMode = UILineBreakMode.HeadTruncation; } _view.TextAlignment = UITextAlignment.Right; break; } // text padding float pl = style.Padding <PaddingLeft> (this, styleBound.Width); float pt = style.Padding <PaddingTop> (this, styleBound.Height); float pr = style.Padding <PaddingRight> (this, styleBound.Width); float pb = style.Padding <PaddingBottom> (this, styleBound.Height); _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr); Bound resultBound = styleBound; // size to content bool sizeByWidth = style.SizeToContentWidth(this); bool sizeByHeight = style.SizeToContentHeight(this); if (sizeByWidth || sizeByHeight) { float measureWidth = sizeByWidth ? maxBound.Width : styleBound.Width; float measureHeight = sizeByHeight ? maxBound.Height : styleBound.Height; SizeF size = _view.SizeThatFits(new SizeF(measureWidth, measureHeight)); float w = sizeByWidth ? size.Width + pl + pr : styleBound.Width; float h = sizeByHeight ? size.Height + pt + pb : styleBound.Height; resultBound = new Bound(w, h); } return(resultBound); }