Skip to content

Unable to change font size for TabView bar items #1269

Closed

Description

@maknz

I can't see a way to change the font size of the labels on TabView bar items. I managed to achieve this on Android with:

    tabView._tabLayout.getTextViewForItemAt(0).setTextSize(10);
    tabView._tabLayout.getTextViewForItemAt(1).setTextSize(10);
    tabView._tabLayout.getTextViewForItemAt(2).setTextSize(10);

but the same approach on iOS (using the appearance proxy: UITabBarItem.appearance().setTitleAttr...) didn't work, I can't be sure what's going on under the hood (are our changes being applied and then overwritten, or just not working outright), but the approaches on Stack Overflow articles that appear to work for regular iOS projects don't seem to be working here, which is strange.

Activity

  1. N3ll commented on Dec 17, 2015

    @N3ll
    Contributor

    @maknz , with the release from yesterday 1.5.1, you should be able to change the font-size only by using CSS.

  2. manijak commented on Dec 17, 2015

    @manijak

    I was wondering what happened to my TabView. :) Great that we can change the size of the TabView button text. But any css applied to TabView in .css is applied to the entire TabView component, also the content of each tab. Is there a way to change font-style & size only to the buttons, and not the entire TabView component?

    I have also noticed that the iOS template-icons work different now with the latest {N} version. They are not color painted by iOS anymore. So if the icon is white, is shows white. If it is black, it show it black ect. So now we have to add the right color on all icons we create?

    Also the same icons do not have a selected color anymore, they stay the same when selected. The only effect indicating that a TabView-button is pressed is the font-color...

    So, in short. How do we change the following in the TabView-buttons with css?

    • Font color normal
    • Font color selected
    • Icon color normal
    • Icon color selected
    • Icon size?
    • Button-bar background color?

    Any documentation regarding the changes? For me, this is a breaking change, visually...

  3. maknz commented on Dec 17, 2015

    @maknz
    Author

    Indeed, I also noticed this. I mean, TabView is the parent element so it makes sense that the styles pass down to its children (i.e. its content), but I think the biggest use case is just wanting to style just the tabs. If there was a way to do that, I'd be happy as larry.

  4. vakrilov commented on Dec 18, 2015

    @vakrilov
    Contributor

    @manijak You are indeed right - all font properties are inheritable and so the content of the tab and the tab item both inherit the font-size. I can see your pain here as you will probably want different styles for those.
    Currently, the problem is that we don't have a separate element/view for the tab-button. It is configured with the properties of the TabViewItem. One possible solution is to introduce a new element (e.g. TabViewTitle) that you can target separately with CSS. For example:

    XML:

    <TabViewItem>
      <TabViewItem.title>
        <TabViewTitle text="FisrtTab" class="tab-title-class" />
      </TabViewItem.title>
      <TabViewItem.view>
        <Label text="Label in Tab1" />
      </TabViewItem.view>
    </TabViewItem>
    

    CSS:

    TabViewTitle {
      ...
    }
    
    .tab-title-class {
      ...
    }
    

    We can also proxy the current properties of the TabViewItem (title, icon etc.) to the new class to maintain backwards-compatibility.

    I would be glad to hear your input on that approach.

  5. vakrilov commented on Dec 18, 2015

    @vakrilov
    Contributor

    @manijak
    We have also added tabsBackgroundColor and selectedColor properties of the TabView - these will work only on the tab items. You can try them out.

  6. manijak commented on Dec 18, 2015

    @manijak

    @vakrilov
    Your suggestion looks good, and it would be great to have something like this out of the box. Not sure about the naming though. "Title". I know that tabButtons on Android are at the top, so the name fits well, but on iOS its on the bottom, so perhaps "TabViewItem.button" & "TabViewButton" would be better?

    This is a bit of a problem now, especially on iOS (not sure about Android), since the last update removed the default iOS-styling of the TabView buttons (which worked well). iOS masked all icons with its own colors for normal and selected states. This should have been kept, but with the ability to override the default behaviour.

    You mentioned the new properties for the TabView, I didn't see them earlier. This is good.
    selectedColor works only on Text, and not the icons. On iOS both the text and the icons change color when selected.

    So we should have:

    textColor
    iconColor
    selectedTextColor
    selectedIconColor
    
  7. added this to the milestone on Dec 21, 2015
  8. amjd commented on Jan 13, 2016

    @amjd

    +1

    On Android, the selectedColor property only changes the color of the bar that highlights the selected tab. It does not have any effect on the selected tab text. A little more control would be nice.

    Also, another important issue with tabs is the inability to style the title independently of the rest of the body. Please consider working on a separate tab element like @vakrilov suggested above.

    Maybe we can make use of CSS pseudo selector :active or :selected for this? That would make styling tabs very intuitive, like so:

    <TabView cssClass="tab" tabsBackgroundColor="#009688" selectedColor="#fff>
      <TabView.items>
        <TabView.item>
          <TabViewItem.title>
            <TabViewTitle>Tab 1</TabViewTitle>
          </TabViewItem.title>
          <TabViewItem.view cssClass="tab-content">
             <Label text="Label in  Tab 1" />
          </TabViewItem.view>
        </TabView.item>
        <TabView.item>
          <TabViewItem.title>
            <TabViewTitle>Tab 2</TabViewTitle>
          </TabViewItem.title>
          <TabViewItem.view cssClass="tab-content">
             <Label text="Label in  Tab 2" />
          </TabViewItem.view>
        </TabView.item>
      </TabView.items>
    </TabView>
    TabViewTitle {
       color: #aaa;
    }
    TabViewTitle:selected {
       color: #bbb;
    }
  9. AntonioCuevaUrraco commented on Jan 18, 2016

    @AntonioCuevaUrraco

    I faced the selected icon color not changing on iOS tabBar as well and I am using this workaround till it is supported.

    var tabBarIcons: Array<string> = [1", "2", "3", "4"];
    var tabBarIconsActive: Array<string> = [1", "2", "3", "4"];
    
    export function pageLoaded(args: EventData) {
        var page: Page = <any>args.object;
        mainTabview = getViewById(page, "main-tabview");
    
           if (!(mainTabview.hasListeners(TabView.selectedIndexChangedEvent))) {
            mainTabview.on(TabView.selectedIndexChangedEvent, (data: SelectedIndexChangedEventData) => {
              //Select new image
              mainTabview.items[data.newIndex].iconSource = tabBarIconsActive[data.newIndex];
              //Unselect old image
              mainTabview.items[data.oldIndex].iconSource = tabBarIcons[data.oldIndex];
           });
          }
        }
  10. added this to the milestone on Feb 8, 2016
  11. 17 remaining items

  12. added this to the 4.3 (TBD) milestone on Jul 27, 2018
  13. larssn commented on Sep 17, 2018

    @larssn

    Seems we could change the font size just fine like so (iOS):

    TabView {
      font-size: 14;
    }
    
  14. modified the milestones: 5.0, 5.1 (TBD) on Nov 14, 2018
  15. modified the milestones: 5.1, 5.2 (TBD) on Dec 5, 2018
  16. MartoYankov commented on Jan 7, 2019

    @MartoYankov
    Contributor

    There is a way to do this for some time now. See #5752.

    Basically the TabView has a new property tabTextFontSize and corresponding CSS rule tab-text-font-size which affects only the tab title text.

    <Page>
      <TabView tabTextFontSize="8">
        <TabView.items>
          <TabViewItem title="First">
            <TabViewItem.view>
              <GridLayout>
                <Label text="First View" verticalAlignment="center" horizontalAlignment="center"/>
              </GridLayout>
            </TabViewItem.view>
          </TabViewItem>
          <TabViewItem title="Second">
            <TabViewItem.view>
              <GridLayout>
                <Label text="Second View" verticalAlignment="center" horizontalAlignment="center"/>
              </GridLayout>
            </TabViewItem.view>
          </TabViewItem>
        </TabView.items>
      </TabView>
    </Page>
    
  17. ghost removed on Jan 7, 2019
  18. Tyler-V commented on Aug 28, 2019

    @Tyler-V

    @MartoYankov how would we achieve this on Angular?

  19. MartoYankov commented on Aug 29, 2019

    @MartoYankov
    Contributor

    @Tyler-V The property itself is on the TabView component, so there shouldn't be any problem with Angular (Angular lacks the TabViewItem components). That being said, I see in your other issue that you are using the new BottomNavigation component, which is a bit different and is still in beta. We will answer you there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions