Ejemplo n.º 1
0
        private void setupText(TTTAttributedLabel attributedLabel, CustomLinkLabel label)
        {
            if ((attributedLabel != null) && (label != null))
            {
                NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();
                paragraphStyle.LineBreakMode = UILineBreakMode.WordWrap;

                if (label.LineSpacing > 0)
                {
                    paragraphStyle.LineHeightMultiple = (float)label.LineSpacing;
                }

                UIElementsHelper.SetCustomLabelParagraphStyle(paragraphStyle, label);

                string text = string.Empty;
                if (!string.IsNullOrEmpty(label.Text))
                {
                    text = label.Text;
                }

                var attString = new NSMutableAttributedString(text, new UIStringAttributes
                {
                    ForegroundColor   = label.TextColor.ToUIColor(),
                    Font              = UIFont.SystemFontOfSize((nfloat)label.FontSize),
                    ParagraphStyle    = paragraphStyle,
                    KerningAdjustment = null
                });

                attributedLabel.LineBreakMode = UILineBreakMode.WordWrap;
                attributedLabel.Lines         = 0;
                attributedLabel.TextAlignment = paragraphStyle.Alignment;

                if (!string.IsNullOrEmpty(label.UrlText) && !string.IsNullOrEmpty(label.Url) && !string.IsNullOrEmpty(label.Text) && label.Text.Contains(label.UrlText))
                {
                    attributedLabel.AddLinkToURL(new NSUrl(label.Url), new NSRange(label.Text.IndexOf(label.UrlText), label.UrlText.Length));
                    attributedLabel.Delegate = new LabelDelegate();
                    attString.AddAttribute(UIStringAttributeKey.ForegroundColor, label.LinkColor.ToUIColor(), new NSRange(label.Text.IndexOf(label.UrlText), label.UrlText.Length));
                }

                attributedLabel.AttributedText = attString;
            }
        }
Ejemplo n.º 2
0
        private void setLineSpacing()
        {
            CustomLabel label = (Element as CustomLabel);

            if ((Control != null) && (label != null) && (label.LineSpacing > 0))
            {
                NSAttributedString controlText = UIElementsHelper.GetUILabelAttributedText(Control);
                if (controlText != null)
                {
                    var labelString    = new NSMutableAttributedString(controlText);
                    var paragraphStyle = new NSMutableParagraphStyle {
                        LineHeightMultiple = (nfloat)label.LineSpacing
                    };

                    UIElementsHelper.SetCustomLabelParagraphStyle(paragraphStyle, label);

                    var style = UIStringAttributeKey.ParagraphStyle;
                    var range = new NSRange(0, labelString.Length);

                    labelString.AddAttribute(style, paragraphStyle, range);
                    Control.AttributedText = labelString;
                }
            }
        }