Change the size of modal View

Shine2701Shine2701 VNMember
edited February 2016 in Xamarin.iOS

Hi,

How can I change the size of modal view?
Currently I want to create a modal view which contain a table view, users can select values from this table.
But whenever the table displays, it go full screen, look like the ModalPresentationStyle is ignored. Also the PreferredContentSize is ignored as well.

Why does this happen? Here is my code:

TableController.cs:

public partial class TableController : UIViewController
    {
        public TableController() : base("TableController", null)
        {
        }

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

            // Release any cached data, images, etc that aren't in use.
        }

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

            UITableView tableView = new UITableView(new CGRect(100, 100, 300, 300));
            tableView.AutoresizingMask = UIViewAutoresizing.All;
            List<string> items = new List<string>() {"1", "2", "3", "4", "5", "6", "10"};
            tableView.Source = new DataSource(items);
            Add(tableView);
        }
    }

Test.cs

public partial class Test : UIViewController
    {
        public Test() : base("Test", null)
        {
        }

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

            // Release any cached data, images, etc that aren't in use.
        }

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

            UIButton text = UIButton.FromType(UIButtonType.RoundedRect);
            text.Frame = new CGRect(10, 100, 100, 50);
            text.SetTitle("Click me.", UIControlState.Normal);
            Add(text);
            this.View.BackgroundColor = UIColor.Blue;

            text.TouchUpInside += (sender, args) =>
            {
                TableController myController = new TableController();
                myController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
                myController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
                myController.PreferredContentSize = new CGSize(300, 400);
                this.PresentModalViewController(myController, true);
            };
        }
    }
Tagged:
Sign In or Register to comment.