コード例 #1
0
ファイル: PlatformLabelBitmap.cs プロジェクト: smremde/Mapsui
        private static CATextLayer CreateCATextLayer(LabelStyle style, string text)
        {
            var label = new CATextLayer();

            var ctFont  = new MonoTouch.CoreText.CTFont(style.Font.FontFamily, (float)style.Font.Size);
            var aString = new MonoTouch.Foundation.NSAttributedString(text,
                                                                      new MonoTouch.CoreText.CTStringAttributes()
            {
                Font = ctFont
            });

            label.SetFont(ctFont);
            label.FontSize        = (float)style.Font.Size;
            label.ForegroundColor = ToCGColor(style.ForeColor);
            label.BackgroundColor = TransparentColor;
            label.ShadowOpacity   = 0;
            label.BorderWidth     = 0;

            label.String = text;

            var size = GetSizeForText(0, aString);

            label.Frame = new RectangleF(0, 0, size.Width, size.Height);

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

            links = new List <NewsCellView.Link>();

            int lengthCounter = 0;
            int i             = 0;

            foreach (var b in blocks)
            {
                var color       = Theme.CurrentTheme.MainTextColor;
                var font        = NewsCellView.BodyFont;
                var anchorBlock = b as BaseEventsViewModel.AnchorBlock;

                if (anchorBlock != null)
                {
                    color = LinkColor;
                    font  = LinkFont.WithSize(LinkFont.PointSize * Theme.CurrentTheme.FontSizeRatio);
                }

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

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

                lengthCounter += strLength;
            }

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

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

                UIFont font = null;
                if (b.Font != null)
                {
                    font = b.Font.WithSize(b.Font.PointSize * Theme.CurrentTheme.FontSizeRatio);
                }
                else
                {
                    if (b.Tapped != null)
                    {
                        font = LinkFont.WithSize(LinkFont.PointSize * Theme.CurrentTheme.FontSizeRatio);
                    }
                }

                if (color == null)
                {
                    color = Theme.CurrentTheme.MainTextColor;
                }
                if (font == null)
                {
                    font = NewsCellView.BodyFont;
                }


                var ctFont = new MonoTouch.CoreText.CTFont(font.Name, font.PointSize);
                var str    = new NSAttributedString(b.Value, new MonoTouch.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 = new NSAction(b.Tapped), Id = i++
                    });
                }

                lengthCounter += strLength;
            }

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

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

                UIFont font = null;
                if (b.Font != null)
                    font = b.Font.WithSize(b.Font.PointSize * Theme.CurrentTheme.FontSizeRatio);
                else
                {
                    if (b.Tapped != null)
                        font = LinkFont.WithSize(LinkFont.PointSize * Theme.CurrentTheme.FontSizeRatio);
                }

                if (color == null)
                    color = Theme.CurrentTheme.MainTextColor;
                if (font == null)
                    font = NewsCellView.BodyFont;

                var ctFont = new MonoTouch.CoreText.CTFont(font.Name, font.PointSize);
                var str = new NSAttributedString(b.Value, new MonoTouch.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 = new NSAction(b.Tapped), Id = i++ });

                lengthCounter += strLength;
            }

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