コード例 #1
0
        private static NSMutableAttributedString AsAttributedString(this ProjectSpan projectSpan)
        {
            var projectColor = MvxColor.ParseHexString(projectSpan.ProjectColor).ToNativeColor();

            var projectNameString = projectSpan.ProjectName;

            if (!string.IsNullOrEmpty(projectSpan.TaskName))
            {
                projectNameString = $"{projectNameString}: {projectSpan.TaskName}";
            }

            var textAttachment = new ProjectTextAttachment(
                projectNameString, projectColor, tokenFont);

            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);
        }
コード例 #2
0
        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 ProjectTextAttachment(
                projectName, projectColor, textVerticalOffset, regularFont.Descender
                );

            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);
        }