Search code examples
cssangularionic-frameworkionic5

Ionic 5 set collapsable header color on iOS


My app UI is complex so I'm giving an example to illustrate my problem. On Ionic 5 I have this code taken directly from the official docs

<ion-header translucent="true">
  <ion-toolbar>   
    <ion-buttons collapse="true" slot="end">
      <ion-button>Click Me</ion-button>
    </ion-buttons> 
    <ion-title>Settings</ion-title>               
  </ion-toolbar>
</ion-header>

<ion-content fullscreen="true">
  <ion-header collapse="condense">              
    <ion-toolbar>      
      <ion-buttons collapse="true" slot="end">
        <ion-button>Click Me</ion-button>
      </ion-buttons>
      <ion-title size="large">Settings</ion-title>
    </ion-toolbar>
    <ion-toolbar>
      <ion-searchbar></ion-searchbar>
    </ion-toolbar>
  </ion-header>

  ...

</ion-content>

If I set the color of the toolbars in a way like <ion-toolbar color="primary"> I get something like this

enter image description here

How can I set the color for the space above the colored toolbar?


Solution

  • Had the same issue as well, controlled all my toolbars css from the global.scss to set background color:

    ion-toolbar {
      background: var(--ion-color-primary) !important;
    }
    

    where --ion-color-primary is my desired color