Popup Positioning

3 Sep 202021 minutes to read

SfPopupLayout allows you to show the Popup content at various position based on the requirement.

Following are the list of options available to show SfPopupLayout at various position.

Methods / Property Description

SfPopupLayout.IsOpen

Shows SfPopupLayout at the center.

SfPopupLayout.Show()

It is similar to SfPopupLayout.IsOpen property.

SfPopupLayout.Show(x-position, y-position)

Shows SfPopupLayout at the specified X and y position.

SfPopupLayout.ShowAtTouchPoint()

Shows SfPopupLayout at the touch point.

SfPopupLayout.ShowRelativeToView(View, RelativePosition)

Shows SfPopupLayout at the position relative to the specified view.

SfPopupLayout.ShowRelativeToView(View, RelativePosition,x-position,y-position)

Shows the SfPopupLayout at an absolute x, y coordinate from the relative position of the specified view.

Center Positioning

SfPopupLayout can be shown at the center by using the following options.

To open the SfPopupLayout, use the SfPopupLayout.IsOpen property as in the following code sample.

  • C#
  • using Syncfusion.iOS.PopupLayout;
    
    namespace GettingStarted
    {
        public class MyViewController:UIViewController
        {
            SfPopupLayout popupLayout;
            CustomView customView;
            UIButton showPopupButton;
            
            public MyViewController()
            {
                popupLayout = new SfPopupLayout();
                popupLayout.Content = GetContentOfPopup();
                this.View.AddSubview(popupLayout);
            }
            private UIView GetContentOfPopup()
            {
                customView = new CustomView();
                customView.BackgroundColor = UIColor.White;
    
                showPopupButton = new UIButton();
                showPopupButton.SetTitle("Click to show Popup", UIControlState.Normal);
                showPopupButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                showPopupButton.BackgroundColor = UIColor.Gray;
                showPopupButton.TouchDown += ShowPopupButton_TouchDown;
                customView.AddSubview(showPopupButton);
    
                return customView;
            }
            private void ShowPopupButton_TouchDown(object sender, EventArgs e)
            {
                  popupLayout.IsOpen = true;
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
                popupLayout.Frame = new CGRect(0, 20, this.View.Frame.Width, this.View.Frame.Height - 20);
            }
        }
    }

    Executing the above codes renders the following output in an iOS device.

    To open the SfPopupLayout, use the SfPopupLayout.Show() as in the following code sample.

  • C#
  • using Syncfusion.iOS.PopupLayout;
    
    namespace GettingStarted
    {
        public class MyViewController:UIViewController
        {
            SfPopupLayout popupLayout;
            CustomView customView;
            UIButton showPopupButton;
            
            public MyViewController()
            {
                popupLayout = new SfPopupLayout();
                popupLayout.Content = GetContentOfPopup();
                this.View.AddSubview(popupLayout);
            }
            private UIView GetContentOfPopup()
            {
                customView = new CustomView();
                customView.BackgroundColor = UIColor.White;
    
                showPopupButton = new UIButton();
                showPopupButton.SetTitle("Click to show Popup", UIControlState.Normal);
                showPopupButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                showPopupButton.BackgroundColor = UIColor.Gray;
                showPopupButton.TouchDown += ShowPopupButton_TouchDown;
                customView.AddSubview(showPopupButton);
    
                return customView;
            }
            private void ShowPopupButton_TouchDown(object sender, EventArgs e)
            {
                //Shows SfPopupLayout at the center of the view.
                popupLayout.Show();  
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
                popupLayout.Frame = new CGRect(0, 20, this.View.Frame.Width, this.View.Frame.Height - 20);
            }
        }
    }

    Executing the above codes renders the following output in an iOS device.

    Absolute Positioning

    SfPopupLayout can be shown at the specified position by using the following method.

    Show At x,y position

    To open the SfPopupLayout in specific X,Y coordinates, use the SfPopupLayout.Show(x-position, y-position) property as in the following code sample.

  • C#
  • using Syncfusion.iOS.PopupLayout;
    
    namespace GettingStarted
    {
        public class MyViewController:UIViewController
        {
            SfPopupLayout popupLayout;
            CustomView customView;
            UIButton showPopupButton;
            
            public MyViewController()
            {
                popupLayout = new SfPopupLayout();
                popupLayout.Content = GetContentOfPopup();
                this.View.AddSubview(popupLayout);
            }
            private UIView GetContentOfPopup()
            {
                customView = new CustomView();
                customView.BackgroundColor = UIColor.White;
    
                showPopupButton = new UIButton();
                showPopupButton.SetTitle("Click to show Popup", UIControlState.Normal);
                showPopupButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                showPopupButton.BackgroundColor = UIColor.Gray;
                showPopupButton.TouchDown += ShowPopupButton_TouchDown;
                customView.AddSubview(showPopupButton);
    
                return customView;
            }
            private void ShowPopupButton_TouchDown(object sender, EventArgs e)
            {
                //Shows SfPopupLayout at x-position 100 and y position 100.
                popupLayout.Show(100, 700);  
    
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
                popupLayout.Frame = new CGRect(0, 20, this.View.Frame.Width, this.View.Frame.Height - 20);
            }
        }
    }

    Executing the above codes renders the following output in an iOS device.

    Show At Touch Point

    To open the SfPopupLayout from the touch point in the screen, use the SfPopupLayout.ShowAtTouchPoint() property as in the following code sample.

  • C#
  • using Syncfusion.iOS.PopupLayout;
    
    namespace GettingStarted
    {
        public class MyViewController:UIViewController
        {
            SfPopupLayout popupLayout;
            CustomView customView;
            UIButton showPopupButton;
            
            public MyViewController()
            {
                popupLayout = new SfPopupLayout();
                popupLayout.Content = GetContentOfPopup();
                this.View.AddSubview(popupLayout);
            }
            private UIView GetContentOfPopup()
            {
                customView = new CustomView();
                customView.BackgroundColor = UIColor.White;
    
                showPopupButton = new UIButton();
                showPopupButton.SetTitle("Click to show Popup", UIControlState.Normal);
                showPopupButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                showPopupButton.BackgroundColor = UIColor.Gray;
                showPopupButton.TouchDown += ShowPopupButton_TouchDown;
                customView.AddSubview(showPopupButton);
    
                return customView;
            }
            private void ShowPopupButton_TouchDown(object sender, EventArgs e)
            {
                //Shows SfPopupLayout at the touch point.
                popupLayout.ShowAtTouchPoint(); 
    
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
                popupLayout.Frame = new CGRect(0, 20, this.View.Frame.Width, this.View.Frame.Height - 20);
            }
        }
    }

    Executing the above codes renders the following output in an iOS device.

    NOTE

    SfPopupLayout.ShowAtTouchPoint() is not applicable for Displaying pop-up when the SfPopupLayout is not set as root view.

    Relative Positioning

    SfPopupLayout can be shown at the relative position by using the following method.

    Show Relative To View

    To open the SfPopupLayout relative to a view, use the SfPopupLayout.ShowRelativeToView(View, RelativePosition) property as in the following code sample.

  • C#
  • using Syncfusion.iOS.PopupLayout;
    
    namespace GettingStarted
    {
        public class MyViewController:UIViewController
        {
            SfPopupLayout popupLayout;
            CustomView customView;
            UIButton showPopupButton;
            
            public MyViewController()
            {
                popupLayout = new SfPopupLayout();
                popupLayout.Content = GetContentOfPopup();
                this.View.AddSubview(popupLayout);
            }
            private UIView GetContentOfPopup()
            {
                customView = new CustomView();
                customView.BackgroundColor = UIColor.White;
    
                showPopupButton = new UIButton();
                showPopupButton.SetTitle("Click to show Popup", UIControlState.Normal);
                showPopupButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                showPopupButton.BackgroundColor = UIColor.Gray;
                showPopupButton.TouchDown += ShowPopupButton_TouchDown;
                customView.AddSubview(showPopupButton);
    
                return customView;
            }
            private void ShowPopupButton_TouchDown(object sender, EventArgs e)
            {
                //Shows SfPopupLayout at the bottom of the label.
                popupLayout.ShowRelativeToView(showPopupButton, RelativePosition.AlignBottom);
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
                popupLayout.Frame = new CGRect(0, 20, this.View.Frame.Width, this.View.Frame.Height - 20);
            }
        }
    }
  • C#
  • // CustomView.cs
    
    public class CustomView : UIView
    {
        public CustomView() : base()
        {
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            this.Subviews[0].Frame = new CGRect(50, 280, 200, 50);
        }
    }

    Executing the above codes renders the following output in an iOS device.

    Absolute relative positioning

    The SfPopupLayout can be displayed at an absolute x, y coordinate from the relative position of the specified view by using the following method.

    To open the SfPopupLayout in the specific x, y coordinate relative to a view, use the SfPopupLayout.ShowRelativeToView(View, RelativePosition,x-position,y-position) method.

    using Syncfusion.iOS.PopupLayout;
    
    namespace GettingStarted
    {
        public class MyViewController:UIViewController
        {
            SfPopupLayout popupLayout;
            CustomView customView;
            UIButton showPopupButton;
            
            public MyViewController()
            {
                popupLayout = new SfPopupLayout();
                popupLayout.Content = GetContentOfPopup();
                this.View.AddSubview(popupLayout);
            }
            private UIView GetContentOfPopup()
            {
                customView = new CustomView();
                customView.BackgroundColor = UIColor.White;
    
                showPopupButton = new UIButton();
                showPopupButton.SetTitle("Click to show Popup", UIControlState.Normal);
                showPopupButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                showPopupButton.BackgroundColor = UIColor.Blue;
                showPopupButton.TouchDown += ShowPopupButton_TouchDown;
                customView.AddSubview(showPopupButton);
    
                return customView;
            }
            private void ShowPopupButton_TouchDown(object sender, EventArgs e)
            {
                //Shows SfPopupLayout at the bottom of the label with absolute relative position.
                popupLayout.ShowRelativeToView(showPopupButton, RelativePosition.AlignBottom,50,50);
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
                popupLayout.Frame = new CGRect(0, 20, this.View.Frame.Width, this.View.Frame.Height - 20);
            }
        }
    }
    // CustomView.cs
    
    public class CustomView : UIView
    {
        public CustomView() : base()
        {
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            this.Subviews[0].Frame = new CGRect(50, 280, 200, 50);
        }
    }

    Executing the above codes renders the following output in an iOS device.

    You can pass both negative and positive values as parameters to the SfPopupLayout.ShowRelativeToView(View, RelativePosition, x-position, y-position). The pop-up will be positioned by considering the relative position as (0, 0) the center point. For example, if you have set the RelativePosition as RelativePosition.BottomRight and RelativeView as a button, bottom right corner of the button will be considered as the 0, 0 point and a negative x-position value will place the pop-up to the left of that point and a positive x-position value will place the pop-up to the right of that point. The same applies for y-position also.

    NOTE

    To open the SfPopupLayout relative to a view without absolute position, you have to pass the x-position and y-position parameters as 0 in the SfPopupLayout.ShowRelativeToView(View, RelativePosition,x-position,y-position).