public static Color?ToNullableColor(this IColorInfo colorInfo) { if (colorInfo != null) { return(new Color(colorInfo.Red, colorInfo.Green, colorInfo.Blue)); } return(null); }
public static UIColor ToNullableColor(this IColorInfo colorInfo) { if (colorInfo != null) { return(UIColor.FromRGB(colorInfo.Red, colorInfo.Green, colorInfo.Blue)); } return(null); }
public static Color ToColorOrTransparent(this IColorInfo colorInfo) { return(ToNullableColor(colorInfo) ?? Color.Transparent); }
public static UIColor ToColorOrClear(this IColorInfo colorInfo) { return(ToNullableColor(colorInfo) ?? UIColor.Clear); }
public override void FromString(string s) { Value = FromHexString(s); }
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); } }
public HueField(Size pickerCenterPointOffset, IColorInfo colorInfo) : base(pickerCenterPointOffset, colorInfo) { }