Xamarin Forms - How to create such shape?

Eye_v_eyE 1 Reputation point
2021-04-08T12:06:38.567+00:00

I wanted to create such navigation at the bottom of the apps. What is the best way to do this? I tried the customer renderer but is too tedious.

85710-image.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-04-09T04:25:39.69+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Which platform do you develop on ?

    If on iOS , we can customize the tabbar with Custom renderer , check my post .

    I made a little modification to meet your requirement .

    iOS Custom Renderer

       [assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabRenderer))]  
       namespace FormsA.iOS  
       {  
           public class MyTabRenderer : TabbedRenderer  
           {  
               public override void ViewDidLoad()  
               {  
                   base.ViewDidLoad();  
         
         
                   for(int i = 0; i < 3; i++)  
                   {  
                       UIButton btn = new UIButton(frame: new CoreGraphics.CGRect(0, 0, i==1?80:60, i == 1 ? 80 : 60));  
                       btn.Tag = i;  
                       this.View.Add(btn);  
         
                       //customize button  
                       btn.ClipsToBounds = true;  
                       btn.Layer.CornerRadius = btn.Frame.Width/2;  
                       btn.BackgroundColor = UIColor.Red;  
                       btn.AdjustsImageWhenHighlighted = false;  
         
                       //move button up  
                       CGPoint center = this.TabBar.Center;  
                       center.X = center.X + (i-1) * 100;  
                       center.Y = center.Y - 20;  
                       btn.Center = center;  
         
                       //button click event  
                       btn.TouchUpInside += (sender, ex) =>  
                       {  
                           //use mssage center to inkove method in Forms project  
         
                           nint tag = ((UIButton)sender).Tag;  
                           MessagingCenter.Send<object, int>(this,"Hi", (int)tag);  
                       };  
                   }  
         
                   //you need to create a curving background image and set here.  
                   this.TabBar.BackgroundImage = UIImage.FromBundle("yourimage.png");  
                
         
                   //disable original behavior  
                   this.ShouldSelectViewController += (UITabBarController tabBarController, UIViewController viewController) =>  
                   {            
                       return false;                 
                   };  
               }  
           }  
       }  
    

    Forms

       //xaml  
         
         
           <ContentPage Title="" BackgroundColor="Green"/>  
           <ContentPage Title="" BackgroundColor="Red"/>  
           <ContentPage Title="" BackgroundColor="Blue"/>  
         
       //code behind   
         
         public TabbedPage1()  
               {  
                   InitializeComponent();  
         
                   //this.BarBackgroundColor = Color.Yellow;  
                   //this.BarTextColor = Color.Red;  
         
                   MessagingCenter.Subscribe<object, int>(this, "Hi", (sender,index) =>  
                   {  
                       this.CurrentPage = this.Children[index];  
                   });  
               }  
    

    86092-capture.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments