带有圆形中央按钮的 Xamarin Forms 导航栏

编程入门 行业动态 更新时间:2024-10-19 00:26:56
本文介绍了带有圆形中央按钮的 Xamarin Forms 导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

是否可以在 Xamarin Forms 中重现这样的底部导航栏?

Is it possible to reproduce a bottom navigation bar like this in Xamarin Forms ?

例如不是使用网格,而是使用真正的导航栏,因此此内容保持静态并且导航发生在导航区域中.

Not with a Grid for example, but with a real navigation bar so this content stay static and navigation occurs in navigation area.

推荐答案

你可以在 iOS 中使用自定义渲染器来实现:

You can use custom renderer to achieve this in iOS:

在 Xamarin.forms 中,创建一个包含 5 个页面的 TabbePage:

In Xamarin.forms, create a TabbePage with 5 pages there:

<ContentPage Title="Tab 1" />
<ContentPage Title="Tab 2" />
<ContentPage Title="" />
<ContentPage Title="Tab 3" />
<ContentPage Title="Tab 4" />

TabbedRenderer 中,添加圆形按钮:

In the TabbedRenderer, add the round button there:

[assembly : ExportRenderer(typeof(TabbedPage),typeof(MyRenderer))]
namespace App325.iOS
{
    public class MyRenderer : TabbedRenderer
    {

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UIButton btn = new UIButton(frame: new CoreGraphics.CGRect(0, 0, 60, 60));
            this.View.Add(btn);

            //customize button
            btn.ClipsToBounds = true;
            btn.Layer.CornerRadius = 30;
            btn.BackgroundColor = UIColor.Red;
            btn.AdjustsImageWhenHighlighted = false;

            //move button up
            CGPoint center = this.TabBar.Center;
            center.Y = center.Y - 20;
            btn.Center = center;

            //button click event
            btn.TouchUpInside += (sender, ex) =>
            {
                //use mssage center to inkove method in Forms project
            };

            //disable jump into third page
            this.ShouldSelectViewController += (UITabBarController tabBarController, UIViewController viewController) =>
            {
                if (viewController == tabBarController.ViewControllers[2])
                {
                    return false;
                }
                return true;
            };
        }
    }
}

这篇关于带有圆形中央按钮的 Xamarin Forms 导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-24 17:34:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:圆形   按钮   中央   Forms   Xamarin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!