Esempio n. 1
0
        public static NSMutableAttributedString GetAttachmentString(
            this string imageName,
            double fontCapHeight,
            UIImageRenderingMode renderingMode = UIImageRenderingMode.AlwaysTemplate)
        {
            var attachment = new NSTextAttachment
            {
                Image = UIImage
                        .FromBundle(imageName)
                        .ImageWithRenderingMode(renderingMode)
            };

            var imageSize = attachment.Image.Size;
            var y         = (fontCapHeight - imageSize.Height) / 2;

            attachment.Bounds = new CGRect(0, y, imageSize.Width, imageSize.Height);

            //There neeeds to be a space before the dot, otherwise the colors don't work
            var result = new NSMutableAttributedString(" ");

            result.AddAttribute(UIStringAttributeKey.Font, UIFont.SystemFontOfSize(0), new NSRange(0, 1));

            var attachmentString = NSAttributedString.FromAttachment(attachment);

            result.Append(attachmentString);

            return(result);
        }
Esempio n. 2
0
        public static NSMutableAttributedString GetAttachmentString(
            this string imageName,
            double fontCapHeight,
            UIImageRenderingMode renderingMode = UIImageRenderingMode.AlwaysTemplate)
        {
            var attachment = new NSTextAttachment
            {
                Image = UIImage
                        .FromBundle(imageName)
                        .ImageWithRenderingMode(renderingMode)
            };

            var imageSize = attachment.Image.Size;
            var y         = (fontCapHeight - imageSize.Height) / 2;

            attachment.Bounds = new CGRect(0, y, imageSize.Width, imageSize.Height);

            var result = new NSMutableAttributedString("");

            if (!UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                // For older iOS versions, there neeeds to be a space before the dot, otherwise the colors don't work
                // in iOS 13, they fixed it and this hack breaks the colors
                result.Append(new NSAttributedString(" "));
                result.AddAttribute(UIStringAttributeKey.Font, UIFont.SystemFontOfSize(0), new NSRange(0, 1));
            }

            var attachmentString = NSAttributedString.FromAttachment(attachment);

            result.Append(attachmentString);

            return(result);
        }
Esempio n. 3
0
        public static void LoadSvg(this UIImageView imageView, string svg, Size size,
                                   UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
        {
            var image = svg.LoadImageFromSvg(size, renderingMode);

            imageView.Image = image;
        }
Esempio n. 4
0
        public static UIImage LoadImageFromSvg(this string svg, Size size,
                                               UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
        {
            var file = ResourceHelper.GetEmbeddedResourceStream(svg);

            return(file.LoadImageFromSvgStream(svg, size, renderingMode));
        }
        public static UIImage LoadImageFromSvgStream(this TextReader fileStream, Size size,
                                                     UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
        {
            var graphic = Graphic.LoadSvg(fileStream);

            //Shame on Size not being Equatable ;)
            if (size.Width <= 0 || size.Height <= 0)
            {
                size = graphic.Size;
            }
            var gSize = graphic.Size;

            if (gSize.Width > size.Width || size.Height > gSize.Height)
            {
                var ratioX = size.Width / gSize.Width;
                var ratioY = size.Height / gSize.Height;
                var ratio  = Math.Min(ratioY, ratioX);
                graphic.Size = size = new Size(gSize.Width * ratio, gSize.Height * ratio);
            }
            var c = Platform.CreateImageCanvas(size, Scale);

            graphic.Draw(c);
            var image = c.GetImage().GetUIImage();

            if (renderingMode != UIImageRenderingMode.Automatic)
            {
                image = image.ImageWithRenderingMode(renderingMode);
            }
            fileStream.Dispose();
            return(image);
        }
        public static void LoadSvg(this UIImageView imageView, Stream svgstream, UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
        {
            var s      = imageView.Bounds.Size;
            var reader = new StreamReader(svgstream);
            var image  = reader.LoadImageFromSvgStream(new Size(s.Width, s.Height), renderingMode);

            imageView.Image = image;
        }
Esempio n. 7
0
 private void SetImageColor(Color iconColor)
 {
     if (Element.Source != null && Control.Image != null)
     {
         UIImageRenderingMode renderingMode = iconColor == null || iconColor == Color.Default || iconColor == Color.Transparent ? UIImageRenderingMode.Automatic : UIImageRenderingMode.AlwaysTemplate;
         Control.Image     = Control.Image.ImageWithRenderingMode(renderingMode);
         Control.TintColor = iconColor.ToUIColor();
     }
 }
Esempio n. 8
0
 public FontIconAppearance(CTFont font,
                           CGColor[] colors = null,
                           UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic,
                           CGColor strokeColor = null,
                           float strokeWidth   = 0)
 {
     Font          = font;
     Colors        = colors ?? new[] { UIColor.DarkGray.CGColor };
     RenderingMode = renderingMode;
     StrokeColor   = strokeColor ?? UIColor.Black.CGColor;
     RenderingMode = renderingMode;
     StrokeWidth   = strokeWidth;
 }
 public static UIImage LoadImageFromSvg(this string svg, Size size,
                                        UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
 {
     try {
         var fileName = System.IO.Path.GetFileNameWithoutExtension(svg);
         var file     = File.OpenText(svg);
         var image    = file.LoadImageFromSvgStream(size, renderingMode);
         image.AccessibilityIdentifier = fileName;
         return(image);
     } catch (Exception ex) {
         Debug.WriteLine(ex);
         Debug.WriteLine("Failed parsing: {0}", svg);
         throw;
     }
 }
Esempio n. 10
0
        void SetOverlay(Color color)
        {
            var formsImage = (Image)Element;

            if (formsImage?.Source == null || formsImage?.IsLoading == true)
            {
                return;
            }

            if (Control is UIImageView imageView && imageView.Image != null)
            {
                originalRenderingMode = imageView.Image.RenderingMode;
                originalTintColor     = imageView.TintColor;
                imageView.Image       = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                imageView.TintColor   = color.ToUIColor();
            }
        }
Esempio n. 11
0
 public static UIImage LoadImageFromSvg(this string svg, Size size,
                                        UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
 {
     try
     {
         var fileName = System.IO.Path.GetFileNameWithoutExtension(svg);
         using (var file = File.OpenText(svg))
         {
             var graphic = Graphic.LoadSvg(file);
             //Shame on Size not being Equatable ;)
             if (size.Width <= 0 || size.Height <= 0)
             {
                 size = graphic.Size;
             }
             var gSize = graphic.Size;
             if (gSize.Width > size.Width || size.Height > gSize.Height)
             {
                 var ratioX = size.Width / gSize.Width;
                 var ratioY = size.Height / gSize.Height;
                 var ratio  = Math.Min(ratioY, ratioX);
                 graphic.Size = size = new Size(gSize.Width * ratio, gSize.Height * ratio);
             }
             var c = Platform.CreateImageCanvas(size, Scale);
             graphic.Draw(c);
             var image = c.GetImage().GetUIImage();
             if (renderingMode != UIImageRenderingMode.Automatic)
             {
                 image = image.ImageWithRenderingMode(renderingMode);
             }
             image.AccessibilityIdentifier = fileName;
             return(image);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         Console.WriteLine("Failed parsing: {0}", svg);
         throw;
     }
 }
Esempio n. 12
0
 public virtual UIImage ImageWithRenderingMode(UIImageRenderingMode renderingMode)
 {
     return(default(UIImage));
 }
Esempio n. 13
0
        public static void LoadSvg(this UIImageView imageView, string svg, UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
        {
            var s = imageView.Bounds.Size;

            LoadSvg(imageView, svg, new Size(s.Width, s.Height), renderingMode);
        }
 public static UIImage LoadImageFromSvgStream(this TextReader fileStream, double size,
                                              UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
 {
     return(fileStream.LoadImageFromSvgStream(new Size(size, size), renderingMode));
 }
 public static UIImage LoadImageFromSvg(this string svg, double size,
                                        UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
 {
     return(svg.LoadImageFromSvg(new Size(size, size), renderingMode));
 }
 public static void LoadSvg(this UIImageView imageView, string svg, double size,
                            UIImageRenderingMode renderingMode = UIImageRenderingMode.Automatic)
 {
     imageView.LoadSvg(svg, new Size(size, size), renderingMode);
 }