how to add a logo to header -bar in ionic

2019-02-01 22:44发布

问题:

I am trying to add a logo in the center of my header bar using Ionic. Any advise on how to do it?

Here is my code

<ion-nav-bar class="bar-light">
<!--Logo-->
<ion-nav-buttons >
<img class="title" src="https://s3-us-west 2.amazonaws.com/s.cdpn.io/139144/sp_symbol_option2_1.png">
</ion-nav-buttons>
<ion-nav-buttons side="left">
<!--Left icons-->
<button class="button button-icon button-clear ion-navicon" ng-click="toggleLeft()"> 
</button></ion-nav-bar>

回答1:

How about doing something like this:

<ion-header-bar align-title="center" class="bar-positive">
  <div class="buttons">
    <button class="button" ng-click="doSomething()">Left Button</button>
  </div>
  <h1 class="title"><img class="title-image" src="http://www.ionicframework.com/img/ionic-logo-white.svg" width="123" height="43" /></h1>
  <div class="buttons">
    <button class="button">Right Button</button>
  </div>
</ion-header-bar>

You can have a look at this plunker as well.

Some extra info in their forum.



回答2:

I have done this simply by the following:

In my template <ion-view title="{{pageTitle}}">

and in my controller $scope.pageTitle = "<img src=\"img/logo-290-90.png\">";



回答3:

Considering that you are using a nav bar, you should use ion-nav-title. Here's an example:

<ion-nav-bar align-title="center">
</ion-nav-bar>
<ion-nav-view>
  <ion-view>
    <ion-nav-title>
      <img src="logo.svg">
    </ion-nav-title>
    <ion-content>
      Some super content here!
    </ion-content>
  </ion-view>
</ion-nav-view>


回答4:

<ion-view>
    <ion-nav-title>
            <img alt="Company Logo1" height="40" src="img/logo-07.png">
            <img alt="Company Logo2" height="40" src="img/logo-08.png">
    </ion-nav-title>
</ion-view>

Change the image height and src according to your taste. :)



回答5:

Put the desired image in "www/img" folder in your app. Then use the below code in index.html

<h1 class="title"><img class="title-image" src="img/mylogo.png" width="123" height="43" /></h1>


回答6:

The following can also be done:

<ion-view  id = "yourHeader">
    <ion-nav-title>
        <div id = "title">YOUR TITLE</div>
        <img src="img/Message.png" class = "peers_msg_img">
        <img src="img/Notification.png" class="peers_profile_img">
        <img src="img/Peers.png" class="peers_alert_img">
     </ion-nav-title>
     <ion-content>
       //Some Content
     </ion-content>
</ion-view>

The following directive is the key:

<ion-nav-title>