protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { IStyleSheetHelper style = stylesheet.Helper; base.Apply(stylesheet, styleBound, maxBound); // background color, borders stylesheet.SetBackgroundSettings(this); // text color _view.TextColor = style.Color(this).ToColorOrClear(); // placeholder color _placeholderColor = style.PlaceholderColor(this).ToNullableColor(); SetupPlaceholder(_placeholder); // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } // padding _view.PaddingLeft = style.PaddingLeft(this, styleBound.Width); _view.PaddingTop = style.PaddingTop(this, styleBound.Height); _view.PaddingRight = style.PaddingRight(this, styleBound.Width); _view.PaddingBottom = style.PaddingBottom(this, styleBound.Height); // text align switch (style.TextAlign(this)) { case TextAlignValues.Left: _view.TextAlignment = UITextAlignment.Left; break; case TextAlignValues.Center: _view.TextAlignment = UITextAlignment.Center; break; case TextAlignValues.Right: _view.TextAlignment = UITextAlignment.Right; break; } _view.RightView = CreateValidationIcon(_view.Font.LineHeight); _view.Text = _text; // size to content by background return(styleBound); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); IStyleSheetHelper style = stylesheet.Helper; // background color, borders stylesheet.SetBackgroundSettings(this); // text color _textColor = style.Color(this).ToColorOrClear(); _view.TextColor = _textColor; // placeholder color _placeholderColor = style.PlaceholderColor(this).ToColorOrClear(); // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } // padding float pl = style.PaddingLeft(this, styleBound.Width); float pt = style.PaddingTop(this, styleBound.Height); float pr = style.PaddingRight(this, styleBound.Width); float pb = style.PaddingBottom(this, styleBound.Height); if (IOSApplicationContext.OSVersion.Major >= 7) { _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr); } // text align switch (style.TextAlign(this)) { case TextAlignValues.Left: _view.TextAlignment = UITextAlignment.Left; break; case TextAlignValues.Center: _view.TextAlignment = UITextAlignment.Center; break; case TextAlignValues.Right: _view.TextAlignment = UITextAlignment.Right; break; } RefreshPlaceholder(); float size = _view.Font.LineHeight; _errorSubview = CreateValidationIcon(size); _errorSubview.Frame = new RectangleF(styleBound.Width - size, pt, size, size); _errorSubview.Hidden = true; _view.AddSubview(_errorSubview); // size to content by background return(styleBound); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); _view.Text = _text; IStyleSheetHelper style = stylesheet.Helper; // background color, borders, background image _backgroundImage = stylesheet.SetBackgroundSettings(this); if (_backgroundImage != null) { _view.Layer.Contents = _backgroundImage.CGImage; _view.BackgroundColor = UIColor.Clear; } // text-format _textFormat = style.TextFormat(this); // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } switch (_textFormat) { case TextFormatValues.Text: _view.Text = _text; // text color _view.TextColor = _textColor = style.Color(this).ToColorOrClear(); // selected-color _selectedColor = style.SelectedColor(this).ToNullableColor(); break; case TextFormatValues.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.Color(this).Hex, "{0}"); // selected-color IColorInfo selectedColor = style.SelectedColor(this); if (selectedColor != null) { _selectedHtmlSpan = string.Format(span, selectedColor.Hex, "{0}"); } SetSpannedText(_textHtmlSpan); break; default: throw new NotImplementedException("Text format not found: " + _textFormat); } // selected-background UIColor selectedBackground = style.SelectedBackground(this).ToNullableColor(); if (selectedBackground != null) { if (_backgroundImage != null) { _selectedBackgroundImage = GetFilteredImage(_backgroundImage, selectedBackground).CGImage; selectedBackground.Dispose(); } else { _selectedBackground = selectedBackground; } } // word wrap bool nowrap = style.WhiteSpace(this) == WhiteSpaceKind.Nowrap; if (!nowrap) { _view.TextContainer.LineBreakMode = UILineBreakMode.WordWrap; _view.TextContainer.MaximumNumberOfLines = 0; } else { _view.TextContainer.LineBreakMode = UILineBreakMode.TailTruncation; _view.TextContainer.MaximumNumberOfLines = 1; } // text align SetTextAlign(style.TextAlign(this), nowrap); // text padding float pl = style.PaddingLeft(this, styleBound.Width); float pt = style.PaddingTop(this, styleBound.Height); float pr = style.PaddingRight(this, styleBound.Width); float pb = style.PaddingBottom(this, styleBound.Height); _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr); // resize by background image IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage); // size to content return(MergeBoundByContent(style, bound, maxBound, _view.TextContainerInset, _backgroundImage != null)); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); IStyleSheetHelper style = stylesheet.Helper; // background color, borders, background image UIImage backgroundImage = stylesheet.SetBackgroundSettings(this); if (backgroundImage != null) { _view.SetBackgroundImage(backgroundImage, UIControlState.Normal); } // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } // word wrap bool nowrap = style.WhiteSpace(this) == WhiteSpaceKind.Nowrap; _view.TitleLabel.LineBreakMode = !nowrap ? UILineBreakMode.WordWrap : UILineBreakMode.TailTruncation; // text-format _textFormat = style.TextFormat(this); switch (_textFormat) { case TextFormatValues.Text: SetText(); // text color _textColor = style.Color(this).ToColorOrClear(); _view.SetTitleColor(_textColor, UIControlState.Normal); // selected-color using (UIColor selectedColor = style.SelectedColor(this).ToNullableColor()) if (selectedColor != null) { _view.SetTitleColor(selectedColor, UIControlState.Highlighted); } break; case TextFormatValues.Html: string whitespace = nowrap ? "nowrap" : "normal"; string span = string.Format( "<span style=\"font-family: {0}; font-size: {1:F0}; color: {2}; white-space: {3}\">{4}</span>" , _view.Font.FamilyName, _view.Font.PointSize, "{0}", whitespace, "{1}"); // text color _textHtmlSpan = string.Format(span, style.Color(this).Hex, "{0}"); // selected-color IColorInfo selectedColorInfo = style.SelectedColor(this); if (selectedColorInfo != null) { _selectedHtmlSpan = string.Format(span, selectedColorInfo.Hex, "{0}"); } SetSpannedText(_textHtmlSpan); break; default: throw new NotImplementedException("Text format not found: " + _textFormat); } // selected-background UIColor selectedBackground = style.SelectedBackground(this).ToNullableColor(); if (selectedBackground != null) { if (backgroundImage != null) { using (UIImage selectedImage = GetFilteredImage(backgroundImage, selectedBackground)) _view.SetBackgroundImage(selectedImage, UIControlState.Highlighted); selectedBackground.Dispose(); } else { _selectedBackground = selectedBackground; } } // text align SetTextAlign(style.TextAlign(this, TextAlignValues.Center), nowrap); { // text padding float pl = style.PaddingLeft(this, styleBound.Width); float pt = style.PaddingTop(this, styleBound.Height); float pr = style.PaddingRight(this, styleBound.Width); float pb = style.PaddingBottom(this, styleBound.Height); _view.ContentEdgeInsets = new UIEdgeInsets(pt, pl, pb, pr); // resize by background image IBound bound = GetBoundByImage(styleBound, maxBound, backgroundImage); // size to content bound = MergeBoundByContent(style, bound, maxBound, _view.ContentEdgeInsets, backgroundImage != null); _view.TitleLabel.PreferredMaxLayoutWidth = bound.Width - pl - pr; return(bound); } }