예제 #1
0
        public static NSMutableAttributedString BuildAttributedString(this ExtendedFont font, string text, UITextAlignment textAlignment = UITextAlignment.Natural)
        {
            if (font == null)
            {
                return(new NSMutableAttributedString(text));
            }

            var attributes = new UIStringAttributes();

            attributes.Font              = font.ToUIFont();
            attributes.ForegroundColor   = font.Color.ToUIColor();
            attributes.BackgroundColor   = UIColor.Clear;
            attributes.KerningAdjustment = font.Kerning;

            if (font.IsUnderlined)
            {
                attributes.UnderlineStyle = NSUnderlineStyle.Single;
            }

            var attribString = new NSMutableAttributedString(text, attributes);

            if (font.LineSpacing != 0)
            {
                var paragraphStyle = new NSMutableParagraphStyle()
                {
                    LineSpacing = (nfloat)font.LineSpacing,
                    Alignment   = textAlignment
                };

                attribString.AddAttribute(UIStringAttributeKey.ParagraphStyle, paragraphStyle, new NSRange(0, attribString.Length));
            }

            return(attribString);
        }
        private static UIBarButtonItem[] SetCustomFontsToToolBars(
            List <UIBarButtonItem> navigationBarItems,
            ExtendedFont toolbarFont)
        {
            navigationBarItems.ForEach(nativeItem =>
            {
                if (toolbarFont != null)
                {
                    var textAttributes = new UITextAttributes()
                    {
                        Font      = toolbarFont.ToUIFont(),
                        TextColor = toolbarFont.Color.ToUIColor(),
                    };
                    nativeItem.SetTitleTextAttributes(textAttributes, UIControlState.Normal);
                    nativeItem.TintColor = toolbarFont.Color.ToUIColor();
                }
            });

            return(navigationBarItems.ToArray());
        }