Reputation: 47
Can anyone please guide me how to create a custom view in Xamarin.iOS using XCode.
Im trying to create a Custom Circular View with the class file. I was able to create a XIB file but not able to create a class file.
Upvotes: 0
Views: 172
Reputation: 121
To continue on what you did, do the following.
Create an empty class and name it CircularView
public partial class CircularView : UIView
{
public static readonly NSString Key = new NSString("CircularView");
public static readonly UINib Nib;
static CircularView()
{
Nib = UINib.FromName("CircularView", NSBundle.MainBundle);
}
protected CircularView(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public static CircularView CreateView()
{
return (CircularView)Nib.Instantiate(null, null)[0];
}
}
Create another class and name it CircularView.designer.cs
[Register ("CircularView")]
partial class CircularView
{
void ReleaseDesignerOutlets ()
{
}
}
BEFORE
<Compile Include="Controls\CircularView.cs" />
<Compile Include="Controls\CircularView.designer.cs" />
AFTER
<Compile Include="Controls\CircularView.cs" />
<Compile Include="Controls\CircularView.designer.cs" >
<DependentUpon>CircularView.cs</DependentUpon>
</Compile>
this will ensure that VS shows the designer file as a child of CircularView.cs
var v = CircularView.CreateView();
vwCustom.Add(v);
where vwCustom is a normal UIView added from Designer in my view controller, you can ofcourse name it anything.
Please let me know if you need further help.
Upvotes: 1