简体   繁体   English

导航栏上的标题在 iOS 上不起作用

[英]Title on navigationbar not working on iOS

I have a timer on the navigation bar which runs after a button click, the timer is working on android but on iOS my timer is not updating.我在导航栏上有一个计时器,它在单击按钮后运行,计时器在 android 上工作,但在 iOS 上我的计时器没有更新。

在此处输入图像描述

在此处输入图像描述

Device.StartTimer(TimeSpan.FromSeconds(1), () =>
            {
                if (cts.IsCancellationRequested)
                {
                    return false;
                }
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {

                        TimeSpan _TimeSpan = DateTime.Now - startAt;


                        ToolbarTimer.Text = _TimeSpan.ToString(@"hh\:mm\:ss");

                    });

                    return true;
                }

            });

For custom Navigationbar you can easily use TitleView (Shell or Naviagtion)对于自定义导航栏,您可以轻松使用 TitleView(Shell 或 Naviagtion)

Try something like this:尝试这样的事情:

<Shell.TitleView>
    <Grid VerticalOptions="Center"
          HorizontalOptions="Center">

        <StackLayout Orientation="Horizontal"
                     HorizontalOptions="Center">

            <Label Text="{Binding Title}" 
                   FontSize="20" 
                   TextColor="White" 
                   VerticalTextAlignment="Center" 
                   HorizontalOptions="Center" />

            <Label Text="{Binding Timer}" 
                   FontSize="20" 
                   TextColor="White" 
                   VerticalTextAlignment="Center" 
                   HorizontalOptions="Center" />

        </StackLayout>

    </Grid>
</Shell.TitleView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM