コード例 #1
0
        private static CGSize MeasureTextSize1(string text, CoreText.CTFont font)   // this method seems to give the wrong width
        // https://stackoverflow.com/questions/11245526/measuring-the-text-width
        {
            var dict = new Foundation.NSDictionary <Foundation.NSString, CoreText.CTFont> (new Foundation.NSString("font"), font);

            return(new Foundation.NSString(text).StringSize(dict));
        }
コード例 #2
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            CGColor LightChartBackground   = ColorFromArgb(248, 248, 248);
            CGColor LightChartGrid         = ColorFromArgb(211, 211, 211);
            CGColor LightChartAxis         = ColorFromArgb(128, 128, 128);
            CGColor LightChartMouse        = ColorFromArgb(32, 92, 166);
            CGColor LightChartLegend       = ColorFromArgb(64, 145, 255);
            CGColor LightChartLineDownload = ColorFromArgb(38, 22, 255);
            CGColor LightChartLineUpload   = ColorFromArgb(0, 90, 0);
            CGColor LightChartWhite        = ColorFromArgb(255, 255, 255);

            m_colorBackground    = LightChartBackground;
            m_colorGrid          = LightChartGrid;
            m_colorAxis          = LightChartAxis;
            m_colorMouse         = LightChartMouse;
            m_colorDownloadGraph = LightChartLineDownload;
            m_colorDownloadLine  = LightChartLineDownload;
            m_colorUploadGraph   = LightChartLineUpload;
            m_colorUploadLine    = LightChartLineUpload;
            //m_colorLegendText = LightChartLegend;
            m_colorDownloadText = LightChartLineDownload;
            m_colorUploadText   = LightChartLineUpload;
            m_colorWhite        = LightChartWhite;

            m_font = new CoreText.CTFont("Menlo", 10);

            m_chart = Engine.Instance.Stats.Charts.ChartsList[m_chartIndex];

            Engine.Instance.Stats.Charts.UpdateEvent += new Core.UI.Charts.UpdateHandler(Charts_UpdateEvent);
        }
コード例 #3
0
ファイル: NewsFeedElement.cs プロジェクト: xNUTs/CodeBucket
        private static Tuple<NSMutableAttributedString,List<NewsCellView.Link>> CreateAttributedStringFromBlocks(UIFont font, UIColor primaryColor, IEnumerable<TextBlock> blocks)
        {
            var attributedString = new NSMutableAttributedString();
            var links = new List<NewsCellView.Link>();

            nint lengthCounter = 0;
            int i = 0;

            foreach (var b in blocks)
            {
                UIColor color = null;
                if (b.Tapped != null)
                    color = LinkColor;

                color = color ?? primaryColor; 

                var ctFont = new CoreText.CTFont(font.Name, font.PointSize);
                var str = new NSAttributedString(b.Value, new CoreText.CTStringAttributes() { ForegroundColor = color.CGColor, Font = ctFont });
                attributedString.Append(str);
                var strLength = str.Length;

                if (b.Tapped != null)
                {
                    var weakTapped = new WeakReference<Action>(b.Tapped);
                    links.Add(new NewsCellView.Link { Range = new NSRange(lengthCounter, strLength), Callback = () => weakTapped.Get()?.Invoke(), Id = i++ });
                }

                lengthCounter += strLength;
            }

            return new Tuple<NSMutableAttributedString, List<NewsCellView.Link>>(attributedString, links);
        }
コード例 #4
0
        public static CGRect MeasureText(string text, SKPaint paint)
        {
            var typeface = (paint.Typeface == null) ? "Helvetica" : paint.Typeface.FamilyName;

            CoreText.CTFont font = new CoreText.CTFont(typeface, paint.TextSize);
            var             size = MeasureTextSize2(text, font);

            return(new CGRect(0, -font.AscentMetric, size.Width, font.AscentMetric + font.DescentMetric));
        }
コード例 #5
0
        private static CGSize MeasureTextSize2(string text, CoreText.CTFont font)
        {
            // https://docs.microsoft.com/en-us/dotnet/api/foundation.nsattributedstring?view=xamarin-ios-sdk-12
            var attributedString = new Foundation.NSAttributedString(text,
                                                                     new CoreText.CTStringAttributes()
            {
                Font = font
            });

            return(attributedString.Size);
        }
コード例 #6
0
ファイル: NewsFeedElement.cs プロジェクト: sicsbd/CodeHub.iOS
        private static Tuple <NSMutableAttributedString, List <NewsCellView.Link> > CreateAttributedStringFromBlocks(UIFont font, UIColor primaryColor, IEnumerable <TextBlock> blocks)
        {
            var attributedString = new NSMutableAttributedString();
            var links            = new List <NewsCellView.Link>();

            nint lengthCounter = 0;
            int  i             = 0;

            CoreText.CTFont ctFont;

            try
            {
                ctFont = new CoreText.CTFont(font.FamilyName, font.PointSize);
            }
            catch
            {
                ctFont = CGFont.CreateWithFontName(font.Name).ToCTFont(font.PointSize);
            }

            foreach (var b in blocks)
            {
                UIColor color = null;
                if (b.Tapped != null)
                {
                    color = LinkColor;
                }

                color = color ?? primaryColor;

                var str = new NSAttributedString(b.Value, new CoreText.CTStringAttributes()
                {
                    ForegroundColor = color.CGColor, Font = ctFont
                });
                attributedString.Append(str);
                var strLength = str.Length;

                if (b.Tapped != null)
                {
                    var weakTapped = new WeakReference <Action>(b.Tapped);
                    links.Add(new NewsCellView.Link {
                        Range = new NSRange(lengthCounter, strLength), Callback = () => weakTapped.Get()?.Invoke(), Id = i++
                    });
                }

                lengthCounter += strLength;
            }

            return(new Tuple <NSMutableAttributedString, List <NewsCellView.Link> >(attributedString, links));
        }
コード例 #7
0
        private static Tuple <NSMutableAttributedString, List <NewsCellView.Link> > CreateAttributedStringFromBlocks(IEnumerable <TextBlock> blocks)
        {
            var attributedString = new NSMutableAttributedString();
            var links            = new List <NewsCellView.Link>();

            nint lengthCounter = 0;
            int  i             = 0;

            foreach (var b in blocks)
            {
                UIColor color = null;
                if (b.Color != null)
                {
                    color = b.Color;
                }
                else
                {
                    if (b.Tapped != null)
                    {
                        color = LinkColor;
                    }
                }

                var font = b.Font ?? UIFont.PreferredSubheadline;
                color = color ?? Theme.CurrentTheme.MainTextColor;
                var ctFont = new CoreText.CTFont(font.Name, font.PointSize);
                var str    = new NSAttributedString(b.Value, new CoreText.CTStringAttributes {
                    ForegroundColor = color.CGColor, Font = ctFont
                });
                attributedString.Append(str);
                var strLength = str.Length;

                if (b.Tapped != null)
                {
                    links.Add(new NewsCellView.Link {
                        Range = new NSRange(lengthCounter, strLength), Callback = b.Tapped, Id = i++
                    });
                }

                lengthCounter += strLength;
            }

            return(new Tuple <NSMutableAttributedString, List <NewsCellView.Link> >(attributedString, links));
        }
コード例 #8
0
ファイル: NewsCellView.cs プロジェクト: thedillonb/CodeBucket
        private static Tuple <NSMutableAttributedString, List <Link> > CreateAttributedStringFromBlocks(UIFont font, UIColor primaryColor, IEnumerable <EventTextBlock> blocks)
        {
            var attributedString = new NSMutableAttributedString();
            var links            = new List <Link>();

            nint lengthCounter = 0;
            int  i             = 0;

            foreach (var b in blocks)
            {
                var tapped = (b as EventAnchorBlock)?.Tapped;

                UIColor color = null;
                if (tapped != null)
                {
                    color = LinkColor;
                }

                color = color ?? primaryColor;

                var ctFont = new CoreText.CTFont(font.Name, font.PointSize);
                var str    = new NSAttributedString(b.Text, new CoreText.CTStringAttributes()
                {
                    ForegroundColor = color.CGColor, Font = ctFont
                });
                attributedString.Append(str);
                var strLength = str.Length;

                if (tapped != null)
                {
                    var weakTapped = new WeakReference <Action>(tapped);
                    links.Add(new Link {
                        Range = new NSRange(lengthCounter, strLength), Callback = () => weakTapped.Get()?.Invoke(), Id = i++
                    });
                }

                lengthCounter += strLength;
            }

            return(new Tuple <NSMutableAttributedString, List <Link> >(attributedString, links));
        }
コード例 #9
0
        private static Tuple<NSMutableAttributedString,List<NewsCellView.Link>> CreateAttributedStringFromBlocks(IEnumerable<TextBlock> blocks)
        {
            var attributedString = new NSMutableAttributedString();
            var links = new List<NewsCellView.Link>();

            nint lengthCounter = 0;
            int i = 0;

            foreach (var b in blocks)
            {
                UIColor color = null;
                if (b.Color != null)
                    color = b.Color;
                else
                {
                    if (b.Tapped != null)
                        color = LinkColor;
                }

                var font = b.Font ?? UIFont.PreferredSubheadline;
                color = color ?? Theme.CurrentTheme.MainTextColor;
                var ctFont = new CoreText.CTFont(font.Name, font.PointSize);
                var str = new NSAttributedString(b.Value, new CoreText.CTStringAttributes { ForegroundColor = color.CGColor, Font = ctFont });
                attributedString.Append(str);
                var strLength = str.Length;

                if (b.Tapped != null)
                    links.Add(new NewsCellView.Link { Range = new NSRange(lengthCounter, strLength), Callback = b.Tapped, Id = i++ });

                lengthCounter += strLength;
            }

            return new Tuple<NSMutableAttributedString, List<NewsCellView.Link>>(attributedString, links);
        }