Example #1
0
        private static void addProjectAttachmentsIfNeeded(TextFieldInfo info, NSMutableAttributedString finalString)
        {
            if (string.IsNullOrEmpty(info.ProjectColor))
            {
                return;
            }

            var color = MvxColor.ParseHexString(info.ProjectColor).ToNativeColor();

            var projectName = new NSAttributedString(info.ProjectName.TruncatedAt(maxTextLength), new UIStringAttributes
            {
                Font            = tokenFont,
                ForegroundColor = color
            });

            var textAttachment = new TokenTextAttachment(
                projectName,
                textVerticalOffset,
                color,
                regularFont.Descender,
                textFieldInfoTokenLeftMargin,
                textFieldInfoTokenRightMargin
                );
            var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment));
            var attributes  = new UIStringAttributes {
                ParagraphStyle = paragraphStyle
            };

            attributes.Dictionary[Project] = new NSObject();
            tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length));

            finalString.Append(tokenString);
        }
        private static NSMutableAttributedString AsAttributedString(this ProjectSpan projectSpan)
        {
            var projectColor = MvxColor.ParseHexString(projectSpan.ProjectColor).ToNativeColor();
            var projectName  = new NSAttributedString(projectSpan.ProjectName.TruncatedAt(maxTextLength), new UIStringAttributes
            {
                Font            = tokenFont,
                ForegroundColor = projectColor
            });

            var textAttachment = new TokenTextAttachment(
                projectName,
                textVerticalOffset,
                projectColor,
                regularFont.Descender,
                textFieldInfoTokenLeftMargin,
                textFieldInfoTokenRightMargin
                );

            var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment));
            var attributes  = createBasicAttributes();

            attributes.Dictionary[ProjectId]    = new NSNumber(projectSpan.ProjectId);
            attributes.Dictionary[ProjectName]  = new NSString(projectSpan.ProjectName);
            attributes.Dictionary[ProjectColor] = new NSString(projectSpan.ProjectColor);
            if (projectSpan.TaskId.HasValue)
            {
                attributes.Dictionary[TaskId]   = new NSNumber(projectSpan.TaskId.Value);
                attributes.Dictionary[TaskName] = new NSString(projectSpan.TaskName);
            }

            tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length));

            return(tokenString);
        }
        private static NSMutableAttributedString AsAttributedString(this TagSpan tagSpan)
        {
            var tagName        = new NSMutableAttributedString(tagSpan.TagName.TruncatedAt(maxTextLength), tagAttributes);
            var textAttachment = new TokenTextAttachment(
                tagName,
                textVerticalOffset,
                regularFont.Descender,
                textFieldInfoTokenLeftMargin,
                textFieldInfoTokenRightMargin
                );
            var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment));
            var attributes  = createBasicAttributes();

            attributes.Dictionary[TagId]   = new NSNumber(tagSpan.TagId);
            attributes.Dictionary[TagName] = new NSString(tagSpan.TagName);
            tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length));

            return(tokenString);
        }