UIButton is not showing up the IOS renderer

AnthonySarrisAnthonySarris AUMember ✭✭

Hi,
I have the following code. I am able to see the image and rectangle around it But I am not able to see the button.
Can you please let me know why it is not working?

public class ImageCorrectionRenderer : PageRenderer
    {



        ImageCorrection imageCorrection;
        UIScrollView scrollView;
        UITextView textView;

        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            imageCorrection = e.NewElement as ImageCorrection;
            var view = NativeView;
        }

        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            var touch = touches.AnyObject as UITouch;

            Console.WriteLine(touch);
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // set the background color of the view to white
            UIImageView imageView;
            scrollView = new UIScrollView(
                new CGRect(0, 0, View.Frame.Width
                                        , View.Frame.Height));
            View.AddSubview(scrollView);

            // create our image view
            imageView = new CropImageView(new CGRect(0, 0, View.Frame.Width
                , View.Frame.Height));

            imageView.Image = UIImage.FromFile(imageCorrection.fourPointData.filePath);
            imageView.ContentMode = UIViewContentMode.ScaleToFill;
            scrollView.AddSubview(imageView);
            // set allow zooming
            scrollView.MaximumZoomScale = 3f;
            scrollView.MinimumZoomScale = .1f;
            scrollView.ViewForZoomingInScrollView += (UIScrollView sv) =>
            {
                return imageView;
            };

            FourPointData fourPointData = imageCorrection.fourPointData;
            Xamarin.Forms.Point[] points = fourPointData.points;
            CGRect position = imagePositionInImageView(imageView);
            CGPoint[] cgPoints = new CGPoint[points.Length];

            nfloat horizontalRatio = imageView.Frame.Size.Width / fourPointData.width;
            nfloat verticalRatio = imageView.Frame.Size.Height / fourPointData.height;

            for (var counter = 0; counter < points.Length; counter++) 
            {
                cgPoints[counter] = new CGPoint((horizontalRatio * points[counter].X), position.Y + (verticalRatio * points[counter].Y));
            }
            var size = new SizeF((float)View.Frame.Width, (float)View.Frame.Height);
            PointF locationOne = new PointF((float)imageView.Frame.X, (float)imageView.Frame.Y);
            DraggablePolygon draggablePolygon = new DraggablePolygon(locationOne, size, cgPoints);
            imageView.AddSubview(draggablePolygon);

            UIButton uiButton = UIButton.FromType(UIButtonType.System);
            uiButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            uiButton.SetTitle("Crop Image",UIControlState.Normal);
            uiButton.TouchUpInside += delegate {
                new UIAlertView("Touch1", "TouchUpInside handled", null, "OK", null).Show();
            };
            imageView.AddSubview(uiButton);
Tagged:

Answers

  • JohnHJohnH GBMember ✭✭✭✭✭
    edited July 2017

    Did you mean to add the button to the imageView, and not to the scrollview or to the View?

  • AnthonySarrisAnthonySarris AUMember ✭✭

    I have tried both but none of them works.

Sign In or Register to comment.