Example #1
0
        public void Autorelease()
        {
            // this same test existed in linksdk.app and linkall.app to test the linker optimizing IL code
            // around [Autorelease] decorated methods. However iOS7 changed it's behavior and returns null now
            using (UIImage img = new UIImage()) {
#if __WATCHOS__
                if (true)
                {
#else
                if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
                {
#endif
#if !__TVOS__
                    Assert.Null(img.StretchableImage(10, 10), "StretchableImage");
#endif
                    Assert.Null(img.CreateResizableImage(new UIEdgeInsets(1, 2, 3, 4)), "CreateResizableImage");
                }
                else
                {
#if !__TVOS__
                    Assert.NotNull(img.StretchableImage(10, 10), "StretchableImage");
#endif
                    Assert.NotNull(img.CreateResizableImage(new UIEdgeInsets(1, 2, 3, 4)), "CreateResizableImage");
                }
            }
        }
        public MySlideriOS()
        {
            this.MaximumTrackTintColor = UIColor.Gray;

            UIImage img = GetImage(new CGRect(0, 0, 400, 400));

            this.SetMinTrackImage(img.CreateResizableImage(new UIEdgeInsets(13, 15, 15, 14)), UIControlState.Normal);
            this.SetMinTrackImage(img.CreateResizableImage(new UIEdgeInsets(13, 15, 15, 14)), UIControlState.Selected);
        }
        static UIImage CreateResizableImage(string image)
        {
            UIEdgeInsets insets        = new UIEdgeInsets(0, 5, 0, 5);
            UIImage      originalImage = UIImage.FromBundle(image);

            return(originalImage.CreateResizableImage(insets));
        }
        void UpdateBackgroundDrawable()
        {
            var drawableName = BaseElement.BackgroundDrawable?.File;

            if (string.IsNullOrEmpty(drawableName))
            {
                return;
            }

            UIImage source = UIImage.FromBundle(drawableName);

            if (!Equals(BaseElement.EdgeInsets, default(EdgeInsets)))
            {
                var mode = BaseElement.ResizeMode == ResizeMode.Stretch
                  ? UIImageResizingMode.Stretch
                  : UIImageResizingMode.Tile;

                source = source.CreateResizableImage(
                    new UIEdgeInsets(BaseElement.EdgeInsets.Top,
                                     BaseElement.EdgeInsets.Left,
                                     BaseElement.EdgeInsets.Bottom,
                                     BaseElement.EdgeInsets.Right),
                    mode
                    );
            }
            Control.Background = source;
        }
Example #5
0
        public static UIImage ButtonImage(UIColor color, float cornerRadius, UIColor shadowColor, UIEdgeInsets shadowInsets)
        {
            UIImage topImage    = ImageWithColor(color, cornerRadius);
            UIImage bottomImage = ImageWithColor(shadowColor, cornerRadius);

            float      totalHeight = EdgeSizeFromCornerRadius(cornerRadius) + shadowInsets.Top + shadowInsets.Bottom;
            float      totalWidth  = EdgeSizeFromCornerRadius(cornerRadius) + shadowInsets.Left + shadowInsets.Right;
            float      topWidth    = EdgeSizeFromCornerRadius(cornerRadius);
            float      topHeight   = EdgeSizeFromCornerRadius(cornerRadius);
            RectangleF topRect     = new RectangleF(shadowInsets.Left, shadowInsets.Top, topWidth, topHeight);
            RectangleF bottomRect  = new RectangleF(0, 0, totalWidth, totalHeight);

            UIGraphics.BeginImageContextWithOptions(new SizeF(totalWidth, totalHeight), false, 0.0f);

            if (!RectangleF.Equals(bottomRect, topRect))
            {
                bottomImage.Draw(bottomRect);
            }
            topImage.Draw(topRect);

            UIImage buttonImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            UIEdgeInsets resizeableInsets = new UIEdgeInsets(cornerRadius + shadowInsets.Top,
                                                             cornerRadius + shadowInsets.Left,
                                                             cornerRadius + shadowInsets.Bottom,
                                                             cornerRadius + shadowInsets.Right);

            return(buttonImage.CreateResizableImage(resizeableInsets));
        }
Example #6
0
        void UpdateBackgroundDrawable()
        {
            string drawableName = BaseElement.ResizableSource?.File;

            if (string.IsNullOrEmpty(drawableName))
            {
                return;
            }

            // TODO Provide property for UIImage resizable insets
            UIImage source = UIImage.FromBundle(drawableName);

            if (!Equals(BaseElement.EdgeInsets, default(EdgeInsets)))
            {
                var mode = BaseElement.ResizeMode == ResizeMode.Stretch
                  ? UIImageResizingMode.Stretch
                  : UIImageResizingMode.Tile;

                source = source.CreateResizableImage(
                    new UIEdgeInsets(BaseElement.EdgeInsets.Top,
                                     BaseElement.EdgeInsets.Left,
                                     BaseElement.EdgeInsets.Bottom,
                                     BaseElement.EdgeInsets.Right),
                    mode
                    );
                Control.ContentMode = UIViewContentMode.ScaleToFill;
            }
            Control.Image = source;
        }
        public static UIImage ToUIImageRounded(this UIColor color, float?cornerRadius = null)
        {
            if (cornerRadius == null || !cornerRadius.HasValue)
            {
                return(ToUIImage(color));
            }

            var scale = UIScreen.MainScreen.Scale;

            int width  = (int)(cornerRadius * scale) + (int)scale;
            int height = (int)(cornerRadius * scale);

            var view = new UIView().WithFrame(0, 0, width, height)
                       .WithBackground(color)
                       .WithTune(tune => tune.Layer.CornerRadius = cornerRadius.Value);

            UIImage result = null;

            UIGraphics.BeginImageContextWithOptions(view.Frame.Size, false, 0);
            {
                view.Layer.RenderInContext(UIGraphics.GetCurrentContext());
                result = UIGraphics.GetImageFromCurrentImageContext();
            }
            UIGraphics.EndImageContext();

            return(result.CreateResizableImage(new UIEdgeInsets(0, cornerRadius.Value, 0, cornerRadius.Value)));
        }
		static ChatBubbleCell (){
			bright = UIImage.FromFile ("Images/Chat/[email protected]");
			bleft = UIImage.FromFile ("Images/Chat/[email protected]");
			sendfalied = UIImage.FromFile("Images/Chat/chat-bubble-undelivered.png").CreateResizableImage(new UIEdgeInsets(11, 11, 17, 18));
			left = bleft.CreateResizableImage (new UIEdgeInsets (10, 16, 18, 26));
			right = bright.CreateResizableImage (new UIEdgeInsets (11, 11, 17, 18));
		}
Example #9
0
        static BubbleCell()
        {
            bright = UIImage.FromFile("green.png");
            bleft  = UIImage.FromFile("grey.png");

            left  = bleft.CreateResizableImage(new UIEdgeInsets(10, 16, 18, 26));
            right = bright.CreateResizableImage(new UIEdgeInsets(11, 11, 17, 18));
        }
Example #10
0
		static BubbleCell ()
		{
			bright = UIImage.FromFile ("green.png");
			bleft = UIImage.FromFile ("grey.png");

			left = bleft.CreateResizableImage (new UIEdgeInsets (10, 16, 18, 26));
			right = bright.CreateResizableImage (new UIEdgeInsets (11, 11, 17, 18));
		}
Example #11
0
		static BubbleCell ()
		{
			var a = new System.Uri ("http://www.google.com", UriKind.Absolute);
			bright = UIImage.FromFile ("green.png");
			bleft = UIImage.FromFile ("grey.png");

			left = bleft.CreateResizableImage (new UIEdgeInsets (10, 16, 18, 26));
			right = bright.CreateResizableImage (new UIEdgeInsets (11, 11, 17, 18));
		}
Example #12
0
        void snippet9()
        {
            // >> chart-drawing-image-resize-cs
            UIImage image = new UIImage("pattern2.png");
            var     fill  = new TKImageFill(image.CreateResizableImage(new UIEdgeInsets(10, 10, 10, 10)));

            fill.ResizingMode = TKImageFillResizingMode.None;
            // << chart-drawing-image-resize-cs
        }
Example #13
0
        public void Initialize()
        {
            gDayImage = new UIImage("calendar_cell.png");
            gDayImage = gDayImage.CreateResizableImage(new UIEdgeInsets(4, 4, 4, 4), UIImageResizingMode.Stretch);

            gCurrentDayImage = new UIImage("calendar_current_cell.png");
            gCurrentDayImage = gCurrentDayImage.CreateResizableImage(new UIEdgeInsets(4, 4, 4, 4), UIImageResizingMode.Stretch);

            gSelectedDayImage = new UIImage("calendar_selected_cell.png");
            gSelectedDayImage = gSelectedDayImage.CreateResizableImage(new UIEdgeInsets(4, 4, 4, 4), UIImageResizingMode.Stretch);
        }
Example #14
0
        public static UIImage WithMinimumSize(this UIImage image, float width, float height)
        {
            var size = new SizeF(width, height);
            var rect = new RectangleF(0, 0, size.Width, size.Height);

            UIGraphics.BeginImageContextWithOptions(size, false, 0.0f);
            image.Draw(rect);
            UIImage resizedImage = UIGraphics.GetImageFromCurrentImageContext();

            return(resizedImage.CreateResizableImage(new UIEdgeInsets(size.Height / 2, size.Width / 2, size.Height / 2, size.Width / 2)));
        }
Example #15
0
        static BubbleCell()
        {
            //var a = new System.Uri ("http://www.google.com", UriKind.Absolute);
            bright     = UIImage.FromFile("green.png");
            bleft      = UIImage.FromFile("grey.png");
            brightblue = UIImage.FromFile("blue.png");

            left      = bleft.CreateResizableImage(new UIEdgeInsets(10, 16, 18, 26));
            right     = bright.CreateResizableImage(new UIEdgeInsets(11, 11, 17, 18));
            rightblue = brightblue.CreateResizableImage(new UIEdgeInsets(11, 11, 17, 18));
        }
Example #16
0
        public void Autorelease()
        {
            using (UIImage img = new UIImage()) {
                // those are the two UIImage instance methods decorated with [Autorelease]
#if !__TVOS__
                img.StretchableImage(10, 10);
#endif
                img.CreateResizableImage(new UIEdgeInsets(1, 2, 3, 4));
                // note: return value is null for iOS7 (and was non-null before it)
                // anyway we care about not crashing due to the linker optimizing the IL, not the return values
            }
        }
Example #17
0
        private UIImage PixelImageWithColor(UIColor color)
        {
            UIGraphics.BeginImageContextWithOptions(new CGSize(1.0f, 1.0f), true, 0);

            color.SetFill();
            UIBezierPath.FromRect(new CGRect(CGPoint.Empty, new CGSize(1.0f, 1.0f))).Fill();
            UIImage img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(img.CreateResizableImage(UIEdgeInsets.Zero));
        }
Example #18
0
        public void Autorelease()
        {
            // this same test existed in linksdk.app and linkall.app to test the linker optimizing IL code
            // around [Autorelease] decorated methods. However iOS7 changed it's behavior and returns null now
            using (UIImage img = new UIImage()) {
                // different versions of iOS returns null or something - so we're not validating the return
                // value since it's not the goal of the test
#if !__TVOS__
                img.StretchableImage(10, 10);
#endif
                img.CreateResizableImage(new UIEdgeInsets(1, 2, 3, 4));
            }
        }
Example #19
0
        public static UIImage ImageWithColor(UIColor imageColor, float cornerRadius)
        {
            float        minEdgeSize = EdgeSizeFromCornerRadius(cornerRadius);
            RectangleF   rect        = new RectangleF(0, 0, minEdgeSize, minEdgeSize);
            UIBezierPath roundedRect = UIBezierPath.FromRoundedRect(rect, cornerRadius);

            roundedRect.LineWidth = 0;
            UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0.0f);
            imageColor.SetFill();
            roundedRect.Fill();
            roundedRect.Stroke();
            roundedRect.AddClip();
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image.CreateResizableImage(new UIEdgeInsets(cornerRadius, cornerRadius, cornerRadius, cornerRadius)));
        }
Example #20
0
        private void RegenerateImages()
        {
            UIImage onSwitchImage = UIImage.FromBundle("TrackBeamThemeImages/switchOnBackground.png");

            onSwitchImage = onSwitchImage.CreateResizableImage(new UIEdgeInsets(0, 20, 0, 20));

            UIImage sliderOnBase = onSwitchImage;

            var sliderOnRect = boundsRect;

            sliderOnRect.Height = sliderOnBase.Size.Height + sliderOnRect.Y;

            UIGraphics.BeginImageContextWithOptions(sliderOnRect.Size, false, scale);
            sliderOnBase.Draw(sliderOnRect);

            sliderOn = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();
        }
Example #21
0
        private UIImage GetKnobImage(nfloat knobWidth)
        {
            UIImage knobTmpImage     = UIImage.FromBundle("TrackBeamThemeImages/switchHandle.png");
            UIImage knobImageStretch = knobTmpImage.CreateResizableImage(new UIEdgeInsets(0, 0, 0, 0));


            var knobRect = new CGRect(0, 0, knobWidth, knobImageStretch.Size.Height);

            UIGraphics.BeginImageContextWithOptions(knobRect.Size, false, scale);
            knobImageStretch.Draw(knobRect);


            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
        private static UIImage CreateOverlayRoundedRectImage()
        {
            UIImage roundedRectImage = null;
            SizeF   imageSize        = new SizeF(2 * kOverlayCornerRadius, 2 * kOverlayCornerRadius);

            UIGraphics.BeginImageContextWithOptions(imageSize, false, UIScreen.MainScreen.Scale);

            var          rect        = new RectangleF(PointF.Empty, imageSize);
            UIBezierPath roundedRect = UIBezierPath.FromRoundedRect(rect, kOverlayCornerRadius);

            OverlayColor.SetColor();
            roundedRect.Fill();

            roundedRectImage = UIGraphics.GetImageFromCurrentImageContext();
            roundedRectImage = roundedRectImage.CreateResizableImage(new UIEdgeInsets(kOverlayCornerRadius, kOverlayCornerRadius, kOverlayCornerRadius, kOverlayCornerRadius));
            UIGraphics.EndImageContext();

            return(roundedRectImage);
        }
Example #23
0
        UIImage CreateBackgroundImage(string drawableName)
        {
            UIImage source = UIImage.FromBundle(drawableName);

            if (!Equals(BaseElement.EdgeInsets, default(EdgeInsets)))
            {
                var mode = BaseElement.ResizeMode == ResizeMode.Stretch
                  ? UIImageResizingMode.Stretch
                  : UIImageResizingMode.Tile;

                source = source.CreateResizableImage(
                    new UIEdgeInsets(BaseElement.EdgeInsets.Top,
                                     BaseElement.EdgeInsets.Left,
                                     BaseElement.EdgeInsets.Bottom,
                                     BaseElement.EdgeInsets.Right),
                    mode
                    );
                Control.ContentMode = UIViewContentMode.ScaleToFill;
            }
            return(source);
        }
Example #24
0
        UIImage CreatePreviewTabBackgroundImage()
        {
            // The preview tab should be flat on the bottom, and have rounded corners on top.
            var size = new SizeF(PreviewTabMinimumWidth, PreviewTabHeight);

            UIGraphics.BeginImageContextWithOptions(size, false, UIScreen.MainScreen.Scale);

            var rect  = new RectangleF(0f, 0f, PreviewTabMinimumWidth, PreviewTabHeight);
            var radii = new SizeF(PreviewTabCornerRadius, PreviewTabCornerRadius);
            var roundedTopCornersRect = UIBezierPath.FromRoundedRect(rect, UIRectCorner.TopLeft | UIRectCorner.TopRight, radii);

            StyleUtilities.ForegroundColor.SetColor();
            roundedTopCornersRect.Fill();
            UIImage previewTabBackgroundImage = UIGraphics.GetImageFromCurrentImageContext();

            var caps = new UIEdgeInsets(0f, PreviewTabCornerRadius, 0f, PreviewTabCornerRadius);

            previewTabBackgroundImage = previewTabBackgroundImage.CreateResizableImage(caps);

            UIGraphics.EndImageContext();
            return(previewTabBackgroundImage);
        }
        public UIButton ButtonForItemIndex(int index)
        {
            SIAlertItem item   = this._Items[index];
            UIButton    button = UIButton.FromType(UIButtonType.Custom);

            button.Tag = index;
            button.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            button.TitleLabel.Font  = (item.Font != null && item.Font != this.ButtonFont) ? item.Font : this.ButtonFont;
            button.SetTitle(item.Title, UIControlState.Normal);
            UIImage normalImage      = null;
            UIImage highlightedImage = null;

            // both custom background images images must be present, otherwise we use the defaults
            if (item.BackgroundImageNormal == null || item.BackgroundImageHighlighted == null)
            {
                switch (item.Type)
                {
                case SIAlertViewButtonType.Cancel:
                    normalImage      = UIImage.FromBundle(@"Images/SIAlertView.bundle/button-cancel");
                    highlightedImage = UIImage.FromBundle(@"Images/SIAlertView.bundle/button-cancel-d");
                    button.SetTitleColor(UIColor.FromWhiteAlpha(0.3f, 1f), UIControlState.Normal);
                    button.SetTitleColor(UIColor.FromWhiteAlpha(0.3f, 1f), UIControlState.Highlighted);
                    break;

                case SIAlertViewButtonType.Destructive:
                    normalImage      = UIImage.FromBundle(@"Images/SIAlertView.bundle/button-destructive");
                    highlightedImage = UIImage.FromBundle(@"Images/SIAlertView.bundle/button-destructive-d");
                    button.SetTitleColor(UIColor.White, UIControlState.Normal);
                    button.SetTitleColor(UIColor.FromWhiteAlpha(1f, 0.8f), UIControlState.Highlighted);
                    break;

                case SIAlertViewButtonType.Default:
                default:
                    normalImage      = UIImage.FromBundle(@"Images/SIAlertView.bundle/button-default");
                    highlightedImage = UIImage.FromBundle(@"Images/SIAlertView.bundle/button-default-d");
                    button.SetTitleColor(UIColor.FromWhiteAlpha(0.4f, 1f), UIControlState.Normal);
                    button.SetTitleColor(UIColor.FromWhiteAlpha(0.4f, 0.8f), UIControlState.Highlighted);
                    break;
                }
            }
            else
            {
                normalImage      = item.BackgroundImageNormal;
                highlightedImage = item.BackgroundImageHighlighted;
            }

            // both images must be present, othrwise we'll fall back to the specified background color
            if (normalImage != null && highlightedImage != null)
            {
                float        hInset = (float)Math.Floor(normalImage.Size.Width / 2);
                float        vInset = (float)Math.Floor(normalImage.Size.Height / 2);
                UIEdgeInsets insets = new UIEdgeInsets(vInset, hInset, vInset, hInset);
                if (normalImage != null)
                {
                    normalImage = normalImage.CreateResizableImage(insets);
                    button.SetBackgroundImage(normalImage, UIControlState.Normal);
                }
                if (highlightedImage != null)
                {
                    highlightedImage = highlightedImage.CreateResizableImage(insets);
                    button.SetBackgroundImage(highlightedImage, UIControlState.Highlighted);
                }
            }
            else if (item.BackgroundColor != null)
            {
                button.BackgroundColor = item.BackgroundColor;
            }

            if (item.TextColorNormal != null)
            {
                button.SetTitleColor(item.TextColorNormal, UIControlState.Normal);
            }
            if (item.TextColorHIghlighted != null)
            {
                button.SetTitleColor(item.TextColorHIghlighted, UIControlState.Highlighted);
            }

            button.TouchUpInside += (o, s) => { ButtonAction(button); };

            return(button);
        }