ionic 頭部和底部+列表+加載動作

ionic 頭部和底部

ion-header-bar
這個是固定在屏幕頂部的一個頭部標題欄。如果給它加上'bar-subheader' 這個樣式,它就是副標題。

用法
<ion-header-bar align-title="left" class="bar-positive"> 
  <div class="buttons"> 
    <button class="button" ng-click="doSomething()">
      Left Button
    </button> 
  </div> 
  <h1 class="title">Title!</h1> 
  <div class="buttons"> 
    <button class="button">
      Right Button
    </button> 
  </div>
</ion-header-bar>

<ion-content> Some content!</ion-content>
API
屬性 類型 描述
align-title(optional) string 這個是對齊 title 的。如果沒有設置,它將會按照手機的默認排版(Ios的默認是居中,Android默認是居左)。它的值可以是 'left','center','right'。
no-tap-scroll(optional) boolean 默認情況下,頭部標題欄在點擊屏幕時內容會滾動到頭部,可以將 no-tap-scroll 設置為 true 來禁止該動作。。它的值是布爾值(true/false)。

ion-footer-bar

知道了 ion-header-bar ,理解ion-footer-bar就輕松多啦!只是 ion-footer-bar 是在屏幕的底部。

用法
<ion-content> Some content!</ion-content>

<ion-footer-bar align-title="left" class="bar-assertive"> 
  <div class="buttons"> 
    <button class="button">Left Button</button> 
  </div> 
  <h1 class="title">Title!</h1> 
  <div class="buttons" ng-click="doSomething()"> 
    <button class="button">Right Button</button> 
  </div>
</ion-footer-bar>
API

與 ion-header-bar 不同的是,ion-footer-bar 只有 align-title 這個 API。

屬性 類型 描述
align-title(optional) string 這個是對齊 title 的。如果沒有設置,它將會按照手機的默認排版(Ios的默認是居中,Android默認是居左)。它的值可以是 'left','center','right'。


ionic 列表操作

列表是一個應用廣泛在幾乎所有移動app中的界面元素。ionList 和 ionItem 這兩個指令還支持多種多樣的交互模式,比如移除其中的某一項,拖動重新排序,滑動編輯等等。

用法
<ion-list> 
  <ion-item ng-repeat="item in items"> 
    Hello, {{item}}! 
  </ion-item>  
</ion-list>
高級用法: 縮略圖,刪除按鈕,重新排序,滑動
<ion-list ng-controller="MyCtrl" show-delete="shouldShowDelete" show-reorder="shouldShowReorder" can-swipe="listCanSwipe"> 
  <ion-item ng-repeat="item in items" class="item-thumbnail-left"> 
    <img ng-src="{{item.img}}"> 
    <h2>{{item.title}}</h2> 
    <p>{{item.description}}</p> 
    <ion-option-button class="button-positive" ng-click="share(item)"> 
      分享 
    </ion-option-button> 

    <ion-option-button class="button-info" ng-click="edit(item)"> 
      編輯 
    </ion-option-button> 

    <ion-delete-button class="ion-minus-circled" ng-click="items.splice($index, 1)"> 

    </ion-delete-button> 

    <ion-reorder-button class="ion-navicon" on-reorder="reorderItem(item, $fromIndex, $toIndex)"> 

    </ion-reorder-button> 

  </ion-item>
</ion-list>
API
屬性 類型 詳情
delegate-handle(可選) 字符串 該句柄定義帶有$ionicListDelegate的列表。
show-delete(可選) 布爾值 列表項的刪除按鈕當前是顯示還是隱藏。
show-reorder(可選) 布爾值 列表項的排序按鈕當前是顯示還是隱藏。
can-swipe(可選) 布爾值 列表項是否被允許滑動顯示選項按鈕。默認:true。
實例

【HTML 代碼:】

<html ng-app="ionicApp"> 

  <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 
    <title>Ionic List Directive</title> 
    <link  rel="stylesheet"> 
    <script src="http://www.runoob.com/static/ionic/js/ionic.bundle.min.js"></script> 
  </head> 

  <body ng-controller="MyCtrl"> 

    <ion-header-bar class="bar-positive"> 
      <div class="buttons"> 
        <button class="button button-icon icon ion-ios-minus-outline" 
             ng-click="data.showDelete = !data.showDelete;   
                       data.showReorder = false"></button> 
      </div> 
      <h1 class="title">Ionic Delete/Option Buttons</h1> 
      <div class="buttons"> 
        <button class="button" ng-click="data.showDelete = false; data.showReorder = !data.showReorder"> Reorder </button> 
      </div> 
    </ion-header-bar> 

    <ion-content> 
      <!-- The list directive is great, but be sure to also checkout the collection repeat directive when scrolling through large lists --> 
      <ion-list show-delete="data.showDelete" show-reorder="data.showReorder"> 
        <ion-item ng-repeat="item in items" item="item" href="#/item/{{item.id}}" class="item-remove-animate"> 
          Item {{ item.id }} 
          <ion-delete-button class="ion-minus-circled" ng-click="onItemDelete(item)"> </ion-delete-button> 
          <ion-option-button class="button-assertive" ng-click="edit(item)"> Edit </ion-option-button> 
          <ion-option-button class="button-calm" ng-click="share(item)"> Share </ion-option-button> 
          <ion-reorder-button class="ion-navicon" on-reorder="moveItem(item, $fromIndex, $toIndex)"></ion-reorder-button> 
        </ion-item> 
      </ion-list> 
    </ion-content> 

  </body>
</html>

【CSS 代碼】

body { 
  cursor: url('http://www.runoob.com/try/demo_source/finger.png'), auto;
}

【JavaScript 代碼】

  angular.module('ionicApp', ['ionic']).controller('MyCtrl', function($scope) { 
    $scope.data = { showDelete: false }; 
    $scope.edit = function(item) { 
      alert('Edit Item: ' + item.id); 
    }; 
    $scope.share = function(item) { 
      alert('Share Item: ' + item.id); 
    }; 
    $scope.moveItem = function(item, fromIndex, toIndex) { 
      $scope.items.splice(fromIndex, 1); 
      $scope.items.splice(toIndex, 0, item); 
    }; 
    $scope.onItemDelete = function(item) { 
      $scope.items.splice($scope.items.indexOf(item), 1); 
    }; 
    $scope.items = [ 
      { id: 0 }, 
      { id: 1 }, 
      { id: 2 }, 
      { id: 3 }, 
      { id: 4 }, 
      { id: 5 }, 
      { id: 6 }, 
      { id: 7 }, 
      { id: 8 }, 
      { id: 9 }, 
      { id: 10 }, 
      { id: 11 }, 
      { id: 12 }, 
      { id: 13 }, 
      { id: 14 }, 
      { id: 15 }, 
      { id: 16 }, 
      { id: 17 }, 
      { id: 18 }, 
      { id: 19 }, 
      { id: 20 }, 
      { id: 21 }, 
      { id: 22 }, 
      { id: 23 }, 
      { id: 24 }, 
      { id: 25 }, 
      { id: 26 }, 
      { id: 27 }, 
      { id: 28 }, 
      { id: 29 }, 
      { id: 30 }, 
      { id: 31 }, 
      { id: 32 }, 
      { id: 33 }, 
      { id: 34 }, 
      { id: 35 }, 
      { id: 36 }, 
      { id: 37 }, 
      { id: 38 }, 
      { id: 39 }, 
      { id: 40 }, 
      { id: 41 }, 
      { id: 42 }, 
      { id: 43 }, 
      { id: 44 }, 
      { id: 45 }, 
      { id: 46 }, 
      { id: 47 }, 
      { id: 48 }, 
      { id: 49 }, 
      { id: 50 } 
    ]; 
  });

嘗試一下 ?



ionic 加載動作

$ionicLoading 是 ionic 默認的一個加載交互效果。里面的內容也是可以在模板里面修改。

用法
angular.module('LoadingApp', ['ionic'])
.controller('LoadingCtrl', function($scope, $ionicLoading) { 
  $scope.show = function() { 
    $ionicLoading.show({ template: 'Loading...' }); 
  }; 
  $scope.hide = function(){ 
    $ionicLoading.hide(); 
  };
});
方法

顯示一個加載效果。

show(opts)
參數 類型 詳情
opts object <small>loading指示器的選項??捎脤傩裕?br>??{string=} template 指示器的html內容。
??{string=} templateUrl 一個加載html模板的url作為指示器的內容。
??{boolean=} noBackdrop 是否隱藏背景。默認情況下它會顯示。
??{number=} delay 指示器延遲多少毫秒顯示。默認為不延遲。
??{number=} duration 等待多少毫秒后自動隱藏指示器。默認情況下,指示器會一直顯示,直到觸發.hide()。</small>

隱藏一個加載效果。

hide()
API
屬性 類型 詳情
delegate-handle(可選) 字符串 該句柄定義帶有$ionicListDelegate的列表。
show-delete(可選) 布爾值 列表項的刪除按鈕當前是顯示還是隱藏。
show-reorder(可選) 布爾值 列表項的排序按鈕當前是顯示還是隱藏。
can-swipe(可選) 布爾值 列表項是否被允許滑動顯示選項按鈕。默認:true。
實例

【HTML 代碼:】

  <html ng-app="ionicApp"> 

    <head> 
      <meta charset="utf-8"> 
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
      <title>Ionic Modal</title> 
      <link  rel="stylesheet"> 
      <script src="http://www.runoob.com/static/ionic/js/ionic.bundle.min.js"></script> 
    </head> 

    <body ng-controller="AppCtrl"> 
      <ion-view title="Home"> 

        <ion-header-bar> 
          <h1 class="title">The Stooges</h1> 
        </ion-header-bar> 

        <ion-content has-header="true"> 
          <ion-list> 
            <ion-item ng-repeat="stooge in stooges" href="#">
              {{stooge.name}}
            </ion-item> 
          </ion-list> 
        </ion-content> 

      </ion-view> 
    </body>

  </html>

【JavaScript 代碼】

angular.module('ionicApp', ['ionic'])
.controller('AppCtrl', function($scope, $timeout, $ionicLoading) { 
  // Setup the loader 
  $ionicLoading.show({ 
    content: 'Loading', 
    animation: 'fade-in', 
    showBackdrop: true, 
    maxWidth: 200, 
    showDelay: 0 
  }); 
  // Set a timeout to clear loader, however you would actually call the $ionicLoading.hide(); method whenever everything is ready or loaded. 
  $timeout(function () { 
    $ionicLoading.hide(); 
    $scope.stooges = [
      {name: 'Moe'}, 
      {name: 'Larry'}, 
      {name: 'Curly'}
    ]; 
  }, 2000); 
});

嘗試一下 ?

$ionicLoadingConfig

設置加載的默認選項:

用法:
var app = angular.module('myApp', ['ionic'])
app.constant('$ionicLoadingConfig', { 
  template: '默認加載模板……'
});
app.controller('AppCtrl', function($scope, $ionicLoading) { 
  $scope.showLoading = function() { 
    $ionicLoading.show(); //配置選項在 $ionicLoadingConfig 設置 
  };
});
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,791評論 6 545
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,795評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 178,943評論 0 384
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 64,057評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,773評論 6 414
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,106評論 1 330
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,082評論 3 450
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,282評論 0 291
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,793評論 1 338
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,507評論 3 361
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,741評論 1 375
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,220評論 5 365
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,929評論 3 351
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,325評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,661評論 1 296
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,482評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,702評論 2 380

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,806評論 25 708
  • 我聽見一聲喊叫,在這溝壑邊緣 在這個冬天,萬物都沉睡的時候 這幾棵盤根的老樹,被驚醒 卑鄙的行為讓我記起春天 濃陰...
    伯爵男主閱讀 663評論 0 2
  • 喜樂操練90天——31《滿足的喜樂》 這些事我已經對你們說了,是要叫我的喜樂存在你們心里,并叫你們的喜樂可以滿足。...
    午后的咖啡與茶閱讀 640評論 0 0
  • 前幾天給老媽打電話說想問下弟弟錄取了沒有,媽媽說,她們已經把他送過去了,剛回來。說爸爸一出學校的門就哭了,淚...
    麥麥尼閱讀 661評論 1 0