Search code examples
xamarin.formsuiviewxamarin.iosxibcustom-renderer

How to change xib's size in Xamarin.iOS designer?


I implemented a CustomRenderer to display a native UIView (which makes use of a xib/nib file) on iOS within my Xamarin.Forms architecture. I followed this tutorial to implement a CustomRenderer for a CustomView in Xamarin.Forms and this tutorial to display an UIView with a xib/nib file in Xamarin.iOS. Please have a look at my repo.

Basically it's working and I can see the NativeView. But it's taking too much space. I'd like to shrink it to the xib's content. Therefore I set Simulated Metric -> Size -> Freeform of the xib's root element. I've hoped taht I could change the size freely then.

enter image description here

Why isn't it possible to change the size by dragging? I can't also set it in the Layout tab because it's greyed out.

enter image description here

Editing the xib as XML file and changing the height is reverted by compiling:

 <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>

and

 <size key="freeformSize" width="414" height="736"/>

Specifying HeighRequest on the usage in the Xamarin.Forms project has no effect. What changes are needed to respect the HeightRequest property? Unfortunately I have few knowledge with native programming in Xamarin.iOS. Do I need to pass the dimensions to my NativeExampleView maybe?

Thanks in advance for any help!


Solution

  • There seems to be an issue with the Visual Studio Designer.

    I tried to follow your steps and faced the same problems as you did. Tested both VS4M and VS4W and in both IDEs had the same issue.

    On the Mac I opened the View with Xcode and once you set the Size to FreeForm and saving, opening the View with Visual Studio I was able to update its size.

    If you have access to Xcode you can try the above.

    In case you don't have a chance to open the View with Xcode you can modify the view manually (source code) by adding this key within the View Node:

    <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
    

    This is the key that Xcode is adding when changing the Size.

    Here you can see the git diff. The red is the VS and the Green means what Xcode added. Show you this so you can have an idea.

    enter image description here

    Another git diff showing a little more information

    enter image description here

    Hope this helps.-