Phuluso Ramulifho
Phuluso Ramulifho

Reputation: 498

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.

enter image description here

enter image description here

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;
                }

            });

Upvotes: 0

Views: 61

Answers (1)

Dom
Dom

Reputation: 569

For custom Navigationbar you can easily use TitleView (Shell or 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>

Upvotes: 1

Related Questions