0

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!

pschlz
  • 173
  • 1
  • 12
  • Hi, have a try this in Forms `` ,I have runned shared project, it work. – Junior Jiang May 08 '19 at 05:45
  • @JuniorJiang-MSFT If you have other views in Forms on the page, they change their postion. So on Forms side it has an effect changing Height-/Widthrrequest. But the native iOS view doesn't change size, other views just overlap it. Maybe change the native view's background color to better see the effect. I also noticed that Padding added to the page isn't also respected by the native view. So how to achieve this? Thanks for your help! – pschlz May 09 '19 at 09:22
  • Yeah, it seems Xib can not be changed directly.If not mind, other ways you can modify them.Eg:`_nativeExampleView.Frame = new CGRect(0, 0, 300, 200);` in Renderer for width and height.If want pass value from Forms, you need to custom bindable property of CustomView .Then get them in renderer. – Junior Jiang May 09 '19 at 09:46
  • But at the end I want the native view to fill up the available width (respecting page's padding etc.) and set the height to keep xib's proportion. Does Xamarin.Forms maybe pass the available space to the custom renderer like in a custom layout? – pschlz May 09 '19 at 15:41

1 Answers1

2

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.-

pinedax
  • 9,246
  • 2
  • 23
  • 30
  • Thanks for your help! Filed an [issue here](https://github.com/xamarin/xamarin-macios/issues/6022). Let's see what they're saying about it. Meanwhile I'll give a try in Xcode. – pschlz May 09 '19 at 06:57
  • After creating the xib in Xcode, setting Size to FreeForm and opening it in Visual Studio on Windows I'm able to change the size per dragging or per Layout tab! I investigated it further and found out that adding the tag `` and removing the tag `` fixes the issue. – pschlz May 09 '19 at 15:56
  • Right. That's what I saw too. Great it worked! Let's wait till Microsoft responds the issue you opened. – pinedax May 09 '19 at 16:37