1

This is a follow-up question, I am using the custom renderer in Shell Custom Renderer reset color set by TabBarUnselectedColor

In my .Net MAUI app, I use a TabBar in AppShell:

    <TabBar>
        <Tab Title="Home" Icon="{StaticResource IconHome}">
            <ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
        </Tab>
        <Tab Title="Coverage&#10;Calculator" Icon="{StaticResource IconCalculator}" >
            <ShellContent ContentTemplate="{DataTemplate calculator:CoverageCalculatorPage}" />
        </Tab>
        <Tab Title="Distributor&#10;Locator" Icon="{StaticResource IconLocator}">
            <ShellContent ContentTemplate="{DataTemplate locator:DistributorsLocatorPage}" />
        </Tab>
        <Tab Title="Scan&#10;QR Code" Icon="{StaticResource IconQrScanner}">
            <ShellContent ContentTemplate="{DataTemplate qrScanner:QrScannerPage}" />
        </Tab>        
        <Tab Title="More" Icon="{StaticResource IconMore}">
            <ShellContent ContentTemplate="{DataTemplate more:MoreFeaturesPage}" />
        </Tab>
    </TabBar>

The Titles of the Tabs are left aligned. Can they be centred?

Currently, it looks like this:

enter image description here

Cfun
  • 8,442
  • 4
  • 30
  • 62
David Shochet
  • 5,035
  • 11
  • 57
  • 105
  • You are talking about ShellContent's Title (not included in your code) not Tab's Title? because Tab's Title is centered – Cfun Sep 28 '22 at 21:43

1 Answers1

1

You can set the alignment of the TextView :

using TextAlignment = Android.Views.TextAlignment;
smallTextView.TextAlignment = TextAlignment.Center;
Cfun
  • 8,442
  • 4
  • 30
  • 62
  • Thank you for your answer. But I actually meant Titles of the TabBar tabs. I added a picture to my question. You said the Title should be already centered, but perhaps it looks like this because the Title has two lines separated by a newline? If so, is there a way to do something to make it look centered? – David Shochet Sep 29 '22 at 12:18
  • 1
    it is better clear now with the picture, never mind my previous comment i was thinking about something else – Cfun Sep 29 '22 at 12:47
  • Thanks, that works! But could you tell how this can be done for iOS? – David Shochet Sep 29 '22 at 14:03
  • 1
    not sure but probably using [textalignment](https://developer.apple.com/documentation/uikit/uitextview/1618618-textalignment) - [possible values](https://developer.apple.com/documentation/uikit/nstextalignment) – Cfun Sep 29 '22 at 14:59