예제 #1
0
        void UpdateTextColor()
        {
            if (Element?.TextType != TextType.Text)
            {
                return;
            }

            if (IsTextFormatted)
            {
                UpdateFormattedText();
                return;
            }

            var textColor = (Color)Element.GetValue(Label.TextColorProperty);

            // default value of color documented to be black in iOS docs
#if __MOBILE__
            Control.TextColor = textColor.ToUIColor(ColorExtensions.LabelColor);
#else
            var alignment     = Element.HorizontalTextAlignment.ToNativeTextAlignment(((IVisualElementController)Element).EffectiveFlowDirection);
            var textWithColor = new NSAttributedString(Element.Text ?? "", font: Element.ToNSFont(), foregroundColor: textColor.ToNSColor(ColorExtensions.Black), paragraphStyle: new NSMutableParagraphStyle()
            {
                Alignment = alignment
            });
            textWithColor = textWithColor.AddCharacterSpacing(Element.Text ?? string.Empty, Element.CharacterSpacing);
            Control.AttributedStringValue = textWithColor;
#endif
            UpdateLayout();
        }
예제 #2
0
        void UpdateTextColor()
        {
            if (IsTextFormatted)
            {
                UpdateFormattedText();
                return;
            }

            var textColor = (Color)Element.GetValue(Label.TextColorProperty);

            if (textColor.IsDefault && Element.TextType == TextType.Html)
            {
                // If no explicit text color has been specified and we're displaying HTML,
                // let the HTML determine the colors
                return;
            }

            // default value of color documented to be black in iOS docs
#if __MOBILE__
            Control.TextColor = textColor.ToUIColor(ColorExtensions.LabelColor);
#else
            var alignment     = Element.HorizontalTextAlignment.ToNativeTextAlignment(((IVisualElementController)Element).EffectiveFlowDirection);
            var textWithColor = new NSAttributedString(Element.Text ?? "", font: Element.ToNSFont(), foregroundColor: textColor.ToNSColor(ColorExtensions.TextColor), paragraphStyle: new NSMutableParagraphStyle()
            {
                Alignment = alignment
            });
            textWithColor = textWithColor.AddCharacterSpacing(Element.Text ?? string.Empty, Element.CharacterSpacing);
            Control.AttributedStringValue = textWithColor;
#endif
            UpdateLayout();
        }
예제 #3
0
        void UpdateText()
        {
            var color = Element.TextColor;

            if (color == Color.Default)
            {
                Control.Title = Element.Text ?? "";
            }
            else
            {
                var textWithColor = new NSAttributedString(Element.Text ?? "", font: Element.Font.ToNSFont(), foregroundColor: color.ToNSColor(), paragraphStyle: new NSMutableParagraphStyle()
                {
                    Alignment = NSTextAlignment.Center
                });
                textWithColor           = textWithColor.AddCharacterSpacing(Element.Text ?? string.Empty, Element.CharacterSpacing);
                Control.AttributedTitle = textWithColor;
            }
        }