本文转自:http://devgirl.org/2014/01/20/ionic-mobile-ui-framework-for-phonegapcordova-developers/

Ionic is both a CSS framework as well as a JavaScript UI library. If you’re an AngularJS developer you will be right at home as Ionic uses AngularJS Extensions via directives to provide user interactions, gestures, animations and more. It follows a View Controller pattern where their built-in Controllers handle the UI interaction with the view.

You don’t have to use the AngularJS extensions to take advantage of Ionic, you can also use the CSS alone which includes a bunch of UI components including tabs, buttons, headers, footers, lists and and others as well.

What Does it Include?

    • Icon Pack – Ionic has a large set of icons to be used with your mobile apps easily, including some animated ones.
    • View Stacks / State Management – Ionic has built-in state management for your views to keep track of navigation history. It gives you the ability to push more than one template into a page at one time as well as push data to a view.
    • Gestures – Ionic incorporates the popular Hammer.js to provide gesture support for things like tap, swipe, drag etc.
    • Side Menus (Slide out) – built-in support for side menus to be toggled when the menu icon is clicked and slide into view.
    • Pull to Refresh – you can easily add pull to refresh capabilities to your scroll area that includes a default icon and animation.
    • Infinite Scroll – an example of how to use it is included in the starters.
    • Full Screen Apps – via the use of the cordova status bar plugin to remove the status bar.
    • Customizable Theme – since the Ionic base theme was built with Sass for the resulting CSS, you can easily go in and customize it to create your own theme. The base look is more of an iOS7 flat look but can be changed as desired.

What Does it Look Like?

Below are a couple of screenshots running samples on the iPad and iPhone Simulator via XCode. The first is using the Ionic CSS only and the 2nd using the AngularJS extensions for tabs and navigation. You should also definitely try out the starter samples from github.

Using CSS only

Here is the snippet of code for the above screenshot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<div class="platform-ios7">
    <div class="bar bar-header bar-positive">
        <button class="button icon ion-navicon button-clear"></button>
        <h1 class="title">My Application </h1>
        <button class="button icon ion-edit button-clear"></button>
    </div>
    <content>
       <div class="list card" style="margin-top:70px">
            <a href="#" class="item item-icon-left">
                <i class="icon ion-home"></i>
                Enter home address
            </a>
            <a href="#" class="item item-icon-left">
                <i class="icon ion-ios7-telephone"></i>
                Enter phone number
            </a>
        </div>
        <ul class="list card">
            <li class="item item-checkbox">
                <label class="checkbox">
                    <input type="checkbox">
                </label>
                Save Password
            </li>
           <li class="item item-checkbox">
                <label class="checkbox">
                    <input type="checkbox">
                </label>
                Auto-Sync
            </li>
        </ul>
        <ul class="card list">
            <li class="item item-toggle">
                <label class="toggle">
                    <input type="checkbox">
                    <div class="track">
                        <div class="handle"></div>
                    </div>
                </label>
                Airplane Mode
            </li>
        </ul>
        <div class="card range">
            <i class="icon ion-volume-low"></i>
            <input type="range" name="volume">
            <i class="icon ion-volume-high"></i>
        </div>
        <div class="card list">
            <label class="item item-radio">
                <input type="radio" name="group">
                <div class="item-content">
                    JavaScript
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
            <label class="item item-radio">
                <input type="radio" name="group">
                <div class="item-content">
                    HTML5
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
        </div>       
        <button class="button button-royal" style="margin-left: 3px">
            Royal Button
        </button>
        <button class="button button-calm">
            Calm Button
        </button>
        <button class="button button-balanced">
            Balanced Button
        </button>
        <button class="button button-energized">
            Energized Button
        </button>
        <button class="button button-clear">
            Clear Button
        </button>
        <button class="button button-dark">
            Dark Button
        </button>
        <button class="button button-positive">
            Positive Button
        </button>
        <button class="button button-full button-balanced">
            Full Width Button
        </button>
    </content>
</div>
<div class="tabs tabs-icon-top tabs-positive">
        <a class="tab-item">
            <i class="icon ion-home"></i>
            Home
        </a>
        <a class="tab-item">
            <i class="icon ion-star"></i>
            Favorites
        </a>
        <a class="tab-item">
            <i class="icon ion-gear-a"></i>
            Settings
        </a>
</div>  
The above sample code is simply to provide the UI using the Ionic CSS classes available. For adding behavior, interaction handling etc, you would either implement that yourself or you can use the AngularJS extensions provided by Ionic. Find out more on that in the next example below.

Using Extensions (via AngularJS Directives)

Navigation via a tab bar is a common mobile paradigm, and a good example to show how you might use Ionic to handle it with their Angular-Ionic extensions. Their Angular-Ionic seed project includes a simple example of how to implement it and a screenshot is shown below, but I uploaded a hosted version to try it out here.

Below are a couple snippets of sample code from the example app that shows how you could use easily implement tab navigation with the Tab Bar Controller (Angular-Ionic extension).

Sample Markup (showing one tab)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
<tabs tabs-style="tabs-icon-top" tabs-type="tabs-positive" animation="fade-in-out"
      tabs-type="tabs-icon-only">
 
<!-- Pets tab -->
    <tab title="Pets" icon="icon ion-home" ng-controller="PetsTabCtrl">
      <content has-header="true" has-tabs="true">
        <list>
          <item ng-repeat="pet in pets" type="item-text-wrap" href="#/pet/{{pet.id}}">
              <h3>{{pet.title}}</h3>
              <p>{{pet.description}}</p>
            </item>
          </item>
        </list>
      </content>
    </tab>
...
//Rest of the tabs here
...
</tabs>

Tab handler code Here’s some example code showing how you would implement handling that tab being shown or hidden in your code:

1
2
3
4
5
6
7
8
9
10
11
12
// A simple controller that fetches a list of data
.controller('PetsTabCtrl', function($scope, Pets) {
  // "Pets" is a service returning mock data (services.js)
  $scope.pets = Pets.all();
 
  $scope.$on('tab.shown', function() {
    // Might do a load here
  });
  $scope.$on('tab.hidden', function() {
    // Might recycle content here
  });
})

More details on the Ionic Tab Bar Controller handling can be foundhere.

Getting Started

You can download or clone the latest release of the Ionic project from Github here. It includes a set of example apps (under /examples/starters) that you can refer to and you can get the Sass source files (under /scss) to customize your theme if desired.

When you’re ready to create your own app, the easiest way I found was to install and use their Node.js tool to create a seed project that contains all of the dependencies for Ionic as well as some sample code.

$ sudo npm install -g ionic $ ionic start myproject

Once the seed project is created, it will look just like a base cordova/phonegap app with platforms, plugins, merges, www etc folders, so at that point you can add the platforms you want via the cordova/phonegap CLI commands. To run the examples shown above, I simply built for iOS using the $ phonegap local build iOS command (or if you’re using cordova CLI $ cordova platform add ios etc) and opened the resulting .xcodeproject (from the platforms/iOS folder) in Xcode and ran it. For a more comprehensive guide on getting started, see their docs here.

My initial experience with Ionic was very positive and I found it well-documented with many code samples, tutorials and a seed project to get up and running quickly, particularly considering it’s alpha state (came out late November 2013), so check it out. I plan to continue to try out their features in my own development and more extensively in the near future as well and will blog features or samples I think might be useful to the rest of you :).

[转]Ionic – Mobile UI Framework for PhoneGap/Cordova Developers的更多相关文章

  1. Hybrid UI framework shootout: Ionic vs. Famo.us vs. F7 vs. OnsenUI

    1 Introduction In the past 2 years I’ve been working intensively on mobile applications, mostly hybr ...

  2. phonegap+cordova+ionic调用原生API

    上一篇博客讲了phonegap+cordova+ionic的环境搭建,今天再来分享一篇cordova调用原生API的文章.从技术角度上来讲,这并不是很难,只是有些细节要是没有注意,或者某些步骤不知道的 ...

  3. WINDOWS下PhoneGap(Cordova)安装笔记

    1.首先下载Node.js  安装nodejs很简单直接点击安装文件下一步直至成功即可,安装notejs的同时npm也会同时安装 成功后打开notejs的命令行工具 输入“node -v”," ...

  4. 开始学习Angular Mobile UI

    介绍 Mobile AngularUI 可以让你使用Twitter Booostrap和Angular JS来开发混合移动App和桌面应用程序. 下面是是一些贯穿整个项目的步骤,我强烈的建议你去继续阅 ...

  5. phonegap,Cordova 使用html5标签

    某些安卓手机的webview使用location.href="tel:123456"不能调到打电话的界面,可以用下面的解决办法: config.xml文件最后加上一行: <a ...

  6. [Phonegap+Sencha Touch] 移动开发36 Phonegap/Cordova项目的图标和启动画面(splashscreen)配置

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/40780111 Phonegap/Cordova项目中的config.xml文件.里面配 ...

  7. 如何安装 PhoneGap / Cordova (for Win10)

    最近需要配置 PhoneGap / Cordova 环境,折腾了一阵子,写篇博客 Mark 一下整个过程. 具体参照了:http://www.assortedgarbage.com/apigee/ 以 ...

  8. PhoneGap+Cordova+SenchaTouch-01-环境搭建

    转http://my.oschina.net/zhongwenhao/blog/369465 环境搭建基于 windows  ,mac系统可以借鉴 1.安装NodeJS 和ruby http://no ...

  9. 跨平台移动开发phonegap/cordova 3.3全系列教程-简介

    一.   跨平台實現架構: phonegap +asp.net+jquery mobile/jqmobi 二.   PhoneGap简介 PhoneGap是一个开源的开发框架,用来构建跨平台的使用HT ...

随机推荐

  1. Wijmo金融图表系列之等量图&成交量柱状图

    Wijmo金融图表有很多类型,我们来一一介绍.之前介绍了平均K线图(Heikin-Ashi)和砖形图,现在我们来一起看看等量图和成交量柱状图. 图表 #3: 等量图(EquiVolume) 等量图和K ...

  2. 【洛谷 p3382】模板-三分法(算法效率)

    题目:给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 解法:与二分法枚举中点使区间分成2份不一样,三分法是枚举三分点,再根据题目的情况修 ...

  3. Orchard中文版源码下载

    本版本基于Orchard1.7.2修改: 新增Bootstrap主题 新增中文语言包 增加了对Sqlite.Orchard数据库的支持 优化工程,减少临时符号生成,增加工程效率 和一些BUG的修正 默 ...

  4. 1秒30000QPS,前后端设计思路

    Q:现在有这样一个需求,在一秒中有3万的支付订单请求,有什么比较好的解决方案吗? PS:我们数据库用的是oracle 程序是java spring mybatis dubbo mq等技术,现在有这样一 ...

  5. weblogic 12c下jxls导出excel报错Could not initialize class org.apache.poi.xssf.usermodel.XSSFVMLDrawing

    周一,开发反馈weblogic 12c下jxls导出excel报错,公司环境和UAT环境均报错,看日志如下: 2016-06-08 09:16:55,825 ERROR org.jxls.util.T ...

  6. MUI - 图片预览(perviewimage)的优化

    主要对mui图片全屏预览插件做了以下三点补充 1.添加了预览图片文字说明,使用的时候需要添加以下css及DOM属性 .mui-slider-img-content { position: absolu ...

  7. SAP中给当前指定的活动用户发系统信息的函数

    函数名:TH_POPUP 输入集团.当前在线用户.Message即可

  8. atitit.短信 验证码  破解  v3 p34  识别 绕过 系统方案规划----业务相关方案 手机验证码  .doc

    atitit.短信 验证码  破解  v3 p34  识别 绕过 系统方案规划----业务相关方案 手机验证码  .doc 1. 手机短信验证码 vs 图片验证码 安全性(破解成本)确实要高一些1 1 ...

  9. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q100-Q103)

    Question 100You create a Web Part.You need to display the number of visits to a SharePoint site coll ...

  10. Android Java类编写规范+优化建议

    本文仅是我个人在实际开发中习惯的编写方式,当然这种方式也是来自很多官方的推荐,所以在一定程度上是可以被模仿套用的.本文将不定期更新~ 零.指导原则 优先保证可读性,不要过分追求代码艺术和效率 在可读性 ...