Exemplo n.º 1
0
        public static NSAttributedString GetAttributedText(this TextFieldInfo self)
        {
            var projectName    = self.PaddedProjectAndTaskName();
            var tags           = self.TagsText();
            var fullText       = $"{self.Text}{projectName}{tags}";
            var result         = new NSMutableAttributedString(fullText);
            var baselineOffset = string.IsNullOrEmpty(self.Text) ? 5 : 3;

            result.AddAttributes(new UIStringAttributes
            {
                ParagraphStyle = paragraphStyle,
                Font           = UIFont.SystemFontOfSize(16, UIFontWeight.Regular),
            }, new NSRange(0, self.Text.Length));

            if (!string.IsNullOrEmpty(self.ProjectColor))
            {
                var color = MvxColor.ParseHexString(self.ProjectColor).ToNativeColor();

                var attributes = new UIStringAttributes
                {
                    ForegroundColor = color,
                    StrokeColor     = strokeColor,
                    BaselineOffset  = baselineOffset,
                    ParagraphStyle  = paragraphStyle,
                    Font            = UIFont.SystemFontOfSize(12, UIFontWeight.Regular),
                };
                attributes.Dictionary[TimeEntryTagsTextView.RoundedBackground] = color.ColorWithAlpha(0.12f);

                result.AddAttributes(attributes, new NSRange(self.Text.Length, projectName.Length));
            }

            if (!string.IsNullOrEmpty(tags))
            {
                var startingPosition = self.Text.Length + projectName.Length;

                for (int i = 0; i < self.Tags.Length; i++)
                {
                    var tagLength = self.Tags[i].Name.Length + 6;

                    var attributes = new UIStringAttributes
                    {
                        BaselineOffset = baselineOffset,
                        ParagraphStyle = paragraphStyle,
                        Font           = UIFont.SystemFontOfSize(12, UIFontWeight.Regular),
                    };
                    attributes.Dictionary[TimeEntryTagsTextView.TagIndex]       = new NSNumber(i);
                    attributes.Dictionary[TimeEntryTagsTextView.RoundedBorders] = strokeColor;
                    result.AddAttributes(attributes, new NSRange(startingPosition, tagLength));

                    startingPosition += tagLength;
                }
            }

            return(result);
        }