コード例 #1
0
        public StylizedStringAttributes(
            UIFont font,
            UIColor color,
            float letterSpace,
            nfloat lineHeightMultiplier,
            StylizedStringCase stringCase,
            UITextAlignment textAlignment   = UITextAlignment.Left,
            NSUnderlineStyle underlineStyle = NSUnderlineStyle.None)
        {
            _stringCase = stringCase;

            NSMutableParagraphStyle paragraphStyle = null;

            if (lineHeightMultiplier != 1 || textAlignment != UITextAlignment.Left)
            {
                paragraphStyle = new NSMutableParagraphStyle
                {
                    LineHeightMultiple = lineHeightMultiplier,
                    Alignment          = textAlignment
                };
            }

            StringAttributes = new UIStringAttributes
            {
                Font              = font,
                ForegroundColor   = color,
                KerningAdjustment = letterSpace,
                ParagraphStyle    = paragraphStyle,
                UnderlineStyle    = underlineStyle
            };
        }
コード例 #2
0
        private void SetUnderLineStyle(UILabel label, NSUnderlineStyle underLineStyle)
        {
            UIStringAttributes attributes = new UIStringAttributes();

            attributes.UnderlineStyle = underLineStyle;
            label.AttributedText      = new NSAttributedString(label.Text, attributes);
        }
コード例 #3
0
        /// <summary>
        ///    Auto-detect links.
        /// </summary>
        /// <remarks>
        ///     If you are matching web URLs you would supply the scheme http://.
        ///     If the pattern matches example.com, which does not have a URL scheme prefix,
        ///     the supplied scheme will be prepended to create http://example.com when the clickable URL link is created.
        /// </remarks>
        /// <param name="self">Target.</param>
        /// <param name="color">Link color.</param>
        /// <param name="style">Link style.</param>
        /// <param name="highlightLink">Flag to highlight link.</param>
        /// <param name="resultLinkNames">List of link names.</param>
        /// <returns>Modified instance of <see cref="T:Foundation.NSMutableAttributedString"/>.</returns>
        public static NSMutableAttributedString DetectLinks(
            this NSMutableAttributedString self,
            UIColor color,
            NSUnderlineStyle style,
            bool highlightLink,
            out string[] resultLinkNames)
        {
            var linkNames = new List <string>();
            var i         = 0;

            foreach (var link in self.Value.FindLinks())
            {
                var range    = new NSRange(link.Index, link.Length);
                var linkName = $"link{i++}";
                var url      = link.Value.ToNSUrl();

                if (url == null)
                {
                    continue; // skip URLs which we can't open
                }

                linkNames.Add(linkName);

                self.AddLink(url, linkName, color, style, range);

                if (highlightLink)
                {
                    self.Foreground(color, range);
                }
            }

            resultLinkNames = linkNames.ToArray();

            return(self);
        }
コード例 #4
0
 public NSAttributedString(string str,
                           NSFont font                         = null,
                           NSColor foregroundColor             = null,
                           NSColor backgroundColor             = null,
                           NSColor strokeColor                 = null,
                           NSColor underlineColor              = null,
                           NSColor strikethroughColor          = null,
                           NSUnderlineStyle underlineStyle     = NSUnderlineStyle.None,
                           NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None,
                           NSParagraphStyle paragraphStyle     = null,
                           float strokeWidth                   = 0,
                           NSShadow shadow                     = null,
                           NSUrl link                  = null,
                           bool superscript            = false,
                           NSTextAttachment attachment = null,
                           NSLigatureType ligature     = NSLigatureType.Default,
                           float baselineOffset        = 0,
                           float kerningAdjustment     = 0,
                           float obliqueness           = 0,
                           float expansion             = 0,
                           NSCursor cursor             = null,
                           string toolTip              = null,
                           int characterShape          = 0,
                           NSGlyphInfo glyphInfo       = null,
                           NSArray writingDirection    = null,
                           bool markedClauseSegment    = false,
                           NSTextLayoutOrientation verticalGlyphForm = NSTextLayoutOrientation.Horizontal,
                           NSTextAlternatives textAlternatives       = null,
                           NSSpellingState spellingState             = NSSpellingState.None) : this(str, NSStringAttributes.ToDictionary(
                                                                                                        font : font,
                                                                                                        foregroundColor : foregroundColor,
                                                                                                        backgroundColor : backgroundColor,
                                                                                                        strokeColor : strokeColor,
                                                                                                        underlineColor : underlineColor,
                                                                                                        strikethroughColor : strikethroughColor,
                                                                                                        underlineStyle : underlineStyle,
                                                                                                        strikethroughStyle : strikethroughStyle,
                                                                                                        paragraphStyle : paragraphStyle,
                                                                                                        strokeWidth : strokeWidth,
                                                                                                        shadow : shadow,
                                                                                                        link : link,
                                                                                                        superscript : superscript,
                                                                                                        attachment : attachment,
                                                                                                        ligature : ligature,
                                                                                                        baselineOffset : baselineOffset,
                                                                                                        kerningAdjustment : kerningAdjustment,
                                                                                                        obliqueness : obliqueness,
                                                                                                        expansion : expansion,
                                                                                                        cursor : cursor,
                                                                                                        toolTip : toolTip,
                                                                                                        characterShape : characterShape,
                                                                                                        glyphInfo : glyphInfo,
                                                                                                        writingDirection : writingDirection,
                                                                                                        markedClauseSegment : markedClauseSegment,
                                                                                                        verticalGlyphForm : verticalGlyphForm,
                                                                                                        textAlternatives : textAlternatives,
                                                                                                        spellingState : spellingState
                                                                                                        ))
 {
 }
コード例 #5
0
        /// <summary>
        ///    Set underline for range.
        /// </summary>
        /// <param name="self">Target.</param>
        /// <param name="underlineStyle">Style.</param>
        /// <param name="range">Range to set underline.</param>
        /// <returns>Modified instance of <see cref="T:Foundation.NSMutableAttributedString"/>.</returns>
        public static NSMutableAttributedString Underline(
            this NSMutableAttributedString self,
            NSUnderlineStyle underlineStyle = NSUnderlineStyle.Single,
            NSRange?range = null)
        {
            var value = NSNumber.FromInt32((int)underlineStyle);

            self.AddAttribute(UIStringAttributeKey.UnderlineStyle, value, range ?? new NSRange(0, self.Length));
            return(self);
        }
コード例 #6
0
        int SetUnderlineStyle(NSString attr, NSUnderlineStyle style,
                              NSUnderlinePattern pattern, bool byWord)
        {
            var value = (int)style | (int)pattern;

            if (byWord)
            {
                value |= (int)NSAttributedString.UnderlineByWordMaskAttributeName;
            }

            SetNumberValue(attr, value);
            return(value);
        }
コード例 #7
0
 /// <summary>
 ///    Set link for range.
 /// </summary>
 /// <param name="self">Target.</param>
 /// <param name="url">URL link.</param>
 /// <param name="linkName">Link name.</param>
 /// <param name="color">Link color.</param>
 /// <param name="style">Link style.</param>
 /// <param name="range">Range to set link.</param>
 /// <returns>Modified instance of <see cref="T:Foundation.NSMutableAttributedString"/>.</returns>
 public static NSMutableAttributedString AddLink(
     this NSMutableAttributedString self,
     NSUrl url,
     string linkName,
     UIColor color,
     NSUnderlineStyle style,
     NSRange range)
 {
     self.AddAttribute(new NSString(linkName), url, range);
     self.AddAttribute(UIStringAttributeKey.UnderlineColor, color, range);
     self.Underline(style, range);
     return(self);
 }
コード例 #8
0
		static internal NSDictionary ToDictionary (
						  UIFont font,
						  UIColor foregroundColor,
						  UIColor backgroundColor,
						  UIColor strokeColor,
						  NSParagraphStyle paragraphStyle,
						  NSLigatureType ligature,
						  float kerning,
						  NSUnderlineStyle underlineStyle,
						  NSShadow shadow,
						  float strokeWidth,
						  NSUnderlineStyle strikethroughStyle)
		{
			var attr = new UIStringAttributes ();
			if (font != null){
				attr.Font = font;
			}
			if (foregroundColor != null){
				attr.ForegroundColor = foregroundColor;
			}
			if (backgroundColor != null){
				attr.BackgroundColor = backgroundColor;
			}
			if (strokeColor != null){
				attr.StrokeColor = strokeColor;
			}
			if (paragraphStyle != null){
				attr.ParagraphStyle = paragraphStyle;
			}
			if (ligature != NSLigatureType.Default){
				attr.Ligature = ligature;
			}
			if (kerning != 0){
				attr.KerningAdjustment = kerning;
			}
			if (underlineStyle != NSUnderlineStyle.None){
				attr.UnderlineStyle = underlineStyle;
			}
			if (shadow != null){
				attr.Shadow = shadow;
			}
			if (strokeWidth != 0){
				attr.StrokeWidth = strokeWidth;
			}
			if (strikethroughStyle != NSUnderlineStyle.None){
				attr.StrikethroughStyle = strikethroughStyle;
			}
			var dict = attr.Dictionary;
			return dict.Count == 0 ? null : dict;
		}				
コード例 #9
0
        public static UILabel WithUnderlinedText(this UILabel self, NSUnderlineStyle style)
        {
            self.AttributedText = new NSAttributedString(self.Text, new UIStringAttributes
            {
                UnderlineStyle = style,
                Font           = self.Font,
                Shadow         = new NSShadow {
                    ShadowColor = UIColor.White, ShadowOffset = new CGSize(0, 1)
                },
                ForegroundColor = self.TextColor
            });

            return(self);
        }
コード例 #10
0
 public NSMutableAttributedString(string str,
                                  UIFont font                         = null,
                                  UIColor foregroundColor             = null,
                                  UIColor backgroundColor             = null,
                                  UIColor strokeColor                 = null,
                                  NSParagraphStyle paragraphStyle     = null,
                                  NSLigatureType ligatures            = NSLigatureType.Default,
                                  float kerning                       = 0,
                                  NSUnderlineStyle underlineStyle     = NSUnderlineStyle.None,
                                  NSShadow shadow                     = null,
                                  float strokeWidth                   = 0,
                                  NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None)
     : this(str, ToDictionary(font, foregroundColor, backgroundColor, strokeColor, paragraphStyle, ligatures, kerning, underlineStyle, shadow, strokeWidth, strikethroughStyle))
 {
 }
コード例 #11
0
		public NSMutableAttributedString (string str,
						  UIFont font = null,
						  UIColor foregroundColor = null,
						  UIColor backgroundColor = null,
						  UIColor strokeColor = null,
						  NSParagraphStyle paragraphStyle = null,
						  NSLigatureType ligatures = NSLigatureType.Default,
						  float kerning = 0,
						  NSUnderlineStyle underlineStyle = NSUnderlineStyle.None,
						  NSShadow shadow = null,
						  float strokeWidth = 0,
						  NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None)
		: this (str, ToDictionary (font, foregroundColor, backgroundColor, strokeColor, paragraphStyle, ligatures, kerning, underlineStyle, shadow, strokeWidth, strikethroughStyle))
		{
		}
コード例 #12
0
 public static NSUnderlineStyle ToKit(this NSUnderlineStyle s) => s;
コード例 #13
0
 public int SetStrikethroughStyle(NSUnderlineStyle style     = NSUnderlineStyle.None,
                                  NSUnderlinePattern pattern = NSUnderlinePattern.Solid, bool byWord = false)
 {
     return(SetUnderlineStyle(NSAttributedString.StrikethroughStyleAttributeName, style, pattern, byWord));
 }
コード例 #14
0
 public int SetUnderlineStyle(NSUnderlineStyle style     = NSUnderlineStyle.None,
                              NSUnderlinePattern pattern = NSUnderlinePattern.Solid, bool byWord = false)
 {
     return(SetUnderlineStyle(NSStringAttributeKey.UnderlineStyle, style, pattern, byWord));
 }
コード例 #15
0
        static internal NSDictionary ToDictionary(
            NSFont font,
            NSColor foregroundColor,
            NSColor backgroundColor,
            NSColor strokeColor,
            NSColor underlineColor,
            NSColor strikethroughColor,
            NSUnderlineStyle underlineStyle,
            NSUnderlineStyle strikethroughStyle,
            NSParagraphStyle paragraphStyle,
            float strokeWidth,
            NSShadow shadow,
            NSUrl link,
            bool superscript,
            NSTextAttachment attachment,
            NSLigatureType ligature,
            float baselineOffset,
            float kerningAdjustment,
            float obliqueness,
            float expansion,
            NSCursor cursor,
            string toolTip,
            int characterShape,
            NSGlyphInfo glyphInfo,
            NSArray writingDirection,
            bool markedClauseSegment,
            NSTextLayoutOrientation verticalGlyphForm,
            NSTextAlternatives textAlternatives,
            NSSpellingState spellingState)
        {
            var attr = new NSStringAttributes();

            if (font != null)
            {
                attr.Font = font;
            }

            if (paragraphStyle != null)
            {
                attr.ParagraphStyle = paragraphStyle;
            }

            if (foregroundColor != null)
            {
                attr.ForegroundColor = foregroundColor;
            }

            if (underlineStyle != NSUnderlineStyle.None)
            {
                attr.UnderlineStyle = (int?)underlineStyle;
            }

            if (superscript)
            {
                attr.Superscript = true;
            }

            if (backgroundColor != null)
            {
                attr.BackgroundColor = backgroundColor;
            }

            if (attachment != null)
            {
                attr.Attachment = attachment;
            }

            if (ligature != NSLigatureType.Default)
            {
                attr.Ligature = ligature;
            }

            if (baselineOffset != 0)
            {
                attr.BaselineOffset = baselineOffset;
            }

            if (kerningAdjustment != 0)
            {
                attr.KerningAdjustment = kerningAdjustment;
            }

            if (link != null)
            {
                attr.Link = link;
            }

            if (strokeWidth != 0)
            {
                attr.StrokeWidth = strokeWidth;
            }

            if (strokeColor != null)
            {
                attr.StrokeColor = strokeColor;
            }

            if (underlineColor != null)
            {
                attr.UnderlineColor = underlineColor;
            }

            if (strikethroughStyle != NSUnderlineStyle.None)
            {
                attr.StrikethroughStyle = (int?)strikethroughStyle;
            }

            if (strikethroughColor != null)
            {
                attr.StrikethroughColor = strikethroughColor;
            }

            if (shadow != null)
            {
                attr.Shadow = shadow;
            }

            if (obliqueness != 0)
            {
                attr.Obliqueness = obliqueness;
            }

            if (expansion != 0)
            {
                attr.Expansion = expansion;
            }

            if (cursor != null)
            {
                attr.Cursor = cursor;
            }

            if (toolTip != null)
            {
                attr.ToolTip = toolTip;
            }

            if (characterShape != 0)
            {
                attr.CharacterShape = 0;
            }

            if (glyphInfo != null)
            {
                attr.GlyphInfo = glyphInfo;
            }

            if (writingDirection != null)
            {
                attr.WritingDirection = writingDirection;
            }

            if (markedClauseSegment)
            {
                attr.MarkedClauseSegment = true;
            }

            if (verticalGlyphForm != NSTextLayoutOrientation.Horizontal)
            {
                attr.VerticalGlyphForm = verticalGlyphForm;
            }

            if (textAlternatives != null)
            {
                attr.TextAlternatives = textAlternatives;
            }

            if (spellingState != NSSpellingState.None)
            {
                attr.SpellingState = spellingState;
            }

            var dict = attr.Dictionary;

            return(dict.Count == 0 ? null : dict);
        }
コード例 #16
0
        public NSAttributedString(string str,
            NSFont font = null,
            NSColor foregroundColor = null,
            NSColor backgroundColor = null,
            NSColor strokeColor = null,
            NSColor underlineColor = null,
            NSColor strikethroughColor = null,
            NSUnderlineStyle underlineStyle = NSUnderlineStyle.None,
            NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None,
            NSParagraphStyle paragraphStyle = null,
            float strokeWidth = 0,
            NSShadow shadow = null,
            NSUrl link = null,
            bool superscript = false,
            NSTextAttachment attachment = null,
            NSLigatureType ligature = NSLigatureType.Default,
            float baselineOffset = 0,
            float kerningAdjustment = 0,
            float obliqueness = 0,
            float expansion = 0,
            NSCursor cursor = null,
            string toolTip = null,
            int characterShape = 0,
            NSGlyphInfo glyphInfo = null,
            NSArray writingDirection = null,
            bool markedClauseSegment = false,
            NSTextLayoutOrientation verticalGlyphForm = NSTextLayoutOrientation.Horizontal,
            NSTextAlternatives textAlternatives = null,
            NSSpellingState spellingState = NSSpellingState.None)
            : this(str, NSStringAttributes.ToDictionary (
				font: font,
				foregroundColor: foregroundColor,
				backgroundColor: backgroundColor,
				strokeColor: strokeColor,
				underlineColor: underlineColor,
				strikethroughColor: strikethroughColor,
				underlineStyle: underlineStyle,
				strikethroughStyle: strikethroughStyle,
				paragraphStyle: paragraphStyle,
				strokeWidth: strokeWidth,
				shadow: shadow,
				link: link,
				superscript: superscript,
				attachment: attachment,
				ligature: ligature,
				baselineOffset: baselineOffset,
				kerningAdjustment: kerningAdjustment,
				obliqueness: obliqueness,
				expansion: expansion,
				cursor: cursor,
				toolTip: toolTip,
				characterShape: characterShape,
				glyphInfo: glyphInfo,
				writingDirection: writingDirection,
				markedClauseSegment: markedClauseSegment,
				verticalGlyphForm: verticalGlyphForm,
				textAlternatives: textAlternatives,
				spellingState: spellingState
			))
        {
        }
コード例 #17
0
 public virtual void UnderlineGlyphRange(NSRange glyphRange, NSUnderlineStyle underlineType, CGRect lineFragmentRect, NSRange lineFragmentGlyphRange, CGPoint containerOrigin)
 {
 }
コード例 #18
0
 public virtual void StrikethroughGlyphRange(NSRange glyphRange, NSUnderlineStyle strikethroughType, CGRect lineFragmentRect, NSRange lineFragmentGlyphRange, CGPoint containerOrigin)
 {
 }
コード例 #19
0
 public virtual void DrawUnderlineForGlyphRange(NSRange glyphRange, NSUnderlineStyle underlineType, CGFloat baselineOffset, CGRect lineFragmentRect, NSRange lineFragmentGlyphRange, CGPoint containerOrigin)
 {
 }
コード例 #20
0
        static internal NSDictionary ToDictionary(
            UIFont font,
            UIColor foregroundColor,
            UIColor backgroundColor,
            UIColor strokeColor,
            NSParagraphStyle paragraphStyle,
            NSLigatureType ligature,
            float kerning,
            NSUnderlineStyle underlineStyle,
#if !WATCH
            NSShadow shadow,
#endif
            float strokeWidth,
            NSUnderlineStyle strikethroughStyle)
        {
            var attr = new UIStringAttributes();

            if (font != null)
            {
                attr.Font = font;
            }
            if (foregroundColor != null)
            {
                attr.ForegroundColor = foregroundColor;
            }
            if (backgroundColor != null)
            {
                attr.BackgroundColor = backgroundColor;
            }
            if (strokeColor != null)
            {
                attr.StrokeColor = strokeColor;
            }
            if (paragraphStyle != null)
            {
                attr.ParagraphStyle = paragraphStyle;
            }
            if (ligature != NSLigatureType.Default)
            {
                attr.Ligature = ligature;
            }
            if (kerning != 0)
            {
                attr.KerningAdjustment = kerning;
            }
            if (underlineStyle != NSUnderlineStyle.None)
            {
                attr.UnderlineStyle = underlineStyle;
            }
#if !WATCH
            if (shadow != null)
            {
                attr.Shadow = shadow;
            }
#endif
            if (strokeWidth != 0)
            {
                attr.StrokeWidth = strokeWidth;
            }
            if (strikethroughStyle != NSUnderlineStyle.None)
            {
                attr.StrikethroughStyle = strikethroughStyle;
            }
            var dict = attr.Dictionary;
            return(dict.Count == 0 ? null : dict);
        }
コード例 #21
0
 /// <summary>
 /// Create an attributed UILabel.
 /// </summary>
 public static UILabel CreateAttrLabel(string text, UIColor textColor, UIFont font, int lines = 0,
                                       UITextAlignment textAlignment = UITextAlignment.Left, UIColor backgroundColor = null, UIColor strokeColor = null,
                                       float lineSpacing             = 0, float kerning = 0, NSUnderlineStyle underlineStyle     = NSUnderlineStyle.None,
                                       NSShadow shadow = null, float strokeWidth        = 0, NSUnderlineStyle strikeThroughStyle = NSUnderlineStyle.None)
 {
     return(new UILabel {
         Lines = lines,
         TextAlignment = textAlignment,
         AttributedText = new NSAttributedString(
             text,
             font,
             textColor,
             backgroundColor,
             strokeColor,
             paragraphStyle: new NSParagraphStyle {
             LineHeightMultiple = 0,
             LineSpacing = lineSpacing
         },
             NSLigatureType.None,
             kerning,
             underlineStyle,
             shadow,
             strokeWidth,
             strikeThroughStyle)
     });
 }
コード例 #22
0
 public static int ToKit(this NSUnderlineStyle s) => (int)s;