Vikram Pote
Vikram Pote

Reputation: 5579

Xamarin iOS how to make different xib for iPad and iPhone with same ViewController

I want to make one view which will contain different UI for iPad and iPhone but both will use the same ViewController.

Will it be possible?

If Yes then how?

Upvotes: 0

Views: 156

Answers (1)

ColeX
ColeX

Reputation: 14463

  1. Create another xib named YourVCName~ipad. enter image description here

  2. Double click the xib,select file's owner class as your viewcontroller.

    enter image description here

  3. Override LoadView method in your viewcontroller.

    public override void LoadView()
    {
        base.LoadView();
        if (UIDevice.CurrentDevice.Model == "iPad")
        {
            string xibName = "ViewController1~ipad";
            UIView v = UINib.FromName(xibName, null).Instantiate(null, null)[0] as UIView;
            View.Add(v);
        }
    }
    

Then you see two different xib can be displayed on different platforms.

Upvotes: 1

Related Questions