Articles in this section
Category / Section

How to integrate .NET MAUI Tab View with iOS native embedding?

4 mins read

In this article, you can learn how to create a .NET MAUI Tab View native-embedded iOS application by following the step-by-step process explained as follows:

Step 1:

Create a .NET iOS application and install the Syncfusion.Maui.TabView NuGet package.

Step 2:

In the project file of the native application, add <UseMaui>true</UseMaui> to enable .NET MAUI support, as demonstrated below.

<PropertyGroup>
. . .
  <Nullable>enable</Nullable>
  <UseMaui>true</UseMaui>
  <ImplicitUsings>enable</ImplicitUsings>
. . .
</PropertyGroup>

Step 3:

Creating a MauiAppBuilder object and using the UseMauiEmbedding function is the standard procedure for initializing .NET MAUI in a native app project.

Use the Build() method on the MauiAppBuilder object to build a MauiApp object. From the MauiApp object, a MauiContext object should be created. Converting .NET MAUI controls to native types will involve using the MauiContext object.

MauiContext? _mauiContext;
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
       // create a new window instance based on the screen size.
       Window = new UIWindow(UIScreen.MainScreen.Bounds);
       MauiAppBuilder builder = MauiApp.CreateBuilder();
       builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
       builder.ConfigureSyncfusionCore();
       // Register the Window.
       builder.Services.Add(new Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(UIWindow), Window));
       MauiApp mauiApp = builder.Build();
       _mauiContext = new MauiContext(mauiApp.Services);
}

Step 4:

Initialize the Tab View control.

MauiContext? _mauiContext;
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
   ...
   SfTabView tabView = new SfTabView();

   ListView listView = new ListView
   {
       RowHeight = 50,
       ItemsSource = new string[] { "James", "Richard", "Clara", "Michael", "Alex", "Clara" },
       ItemTemplate = new DataTemplate(() =>
       {
           var grid = new Grid
           {
               Margin = new Thickness(10, 5)
           };
           var label = new Label
           {
               ...
           };
           label.SetBinding(Label.TextProperty, ".");
           
           grid.Children.Add(label);
   
           return new ViewCell { View = grid };
       })
   };
   
   Grid favoritesGrid = new Grid { };
   favoritesGrid.Children.Add(listView);
   ...
   var tabItems = new TabItemCollection
   {
       new SfTabItem()
       {
           Header = "FAVOURITES",
           Content = favoritesGrid
       },
       ...
   };
   
   tabView.Items = tabItems;
   ...
}

Step 5:

Convert the Tab View into a UIView compatible with the Maui platform. Create a UIViewController, add the Maui Tab View to its sub view, and set it as the root view controller of the main window. Makes the main window visible.

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
   ...
   UIView mauiView = tabView.ToPlatform(_mauiContext);
   mauiView.Frame = Window!.Frame;

   // create UIViewController 
   var vc = new UIViewController();
   vc.View!.AddSubview(mauiView);

   Window.RootViewController = vc;

   // make the window visible
   Window.MakeKeyAndVisible();
   ...
}

Output

TabView_Native_Embedding_iOS.png

Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to integrate .NET MAUI Tab View with an iOS native embedding.

You can refer to our .NET MAUI Tab View feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Tab View documentation to understand how to present and manipulate data.

You can check out our .NET MAUI components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Tab View and other .NET MAUI components.

Please let us know in the comments section below if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied