Sencha Touch开发实例:新浪微博iPhone界面

移动开发 iOS 移动应用
虽然Sencha Touch提供相当多的原生UI组件,但是利用原生UI开发出来的Web App的UI未必能完全满足手机上的UI设计。本文将以iPhone版本的新浪微博的“更多”界面,介绍如何利用Sencha Touch设计“更多”的界面。

相信不少Sencha Touch的粉丝们都为JavaScript能开发出手机Web App应用而感到兴奋。本次示例将以iPhone界面作为参考,使用Sencha Touch开发设计模仿iPhone界面。

首先,将以iPhone下述的界面目标作为参考:

Sencha Touch开发实例:新浪微博iPhone界面

Sencha Touch将采用以下UI组件:

Ext.Panel Ext.List

首先,建立一个html 5页面和一个js页面,如下代码:

  1. <!DOCTYPE HTML> 
  2. <html> 
  3.     <head> 
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  5.         <title>demos</title> 
  6.         <link rel="stylesheet" type="text/css" href="sencha-touch.css"  /> 
  7.         <script type="text/javascript" src="sencha-touch-debug.js"></script> 
  8.         <script type="text/javascript" src="sencha.js" charset="utf-8"></script> 
  9.     </head> 
  10.     <body> 
  11.     </body> 
  12.     </html> 

sencha.js先增加setup以便文档加载完后初始化Panel组件,如下代码:

  1. Ext.setup({ 
  2.     onReady: function() { 
  3.         var moreObj; 
  4.         moreObj = Ext.extend(Ext.Panel, { 
  5.             layout : 'card'
  6.             initComponent : function() { 
  7.                 moreObj.superclass.initComponent.call(this,arguments); 
  8.             } 
  9.         }) 
  10.   
  11.         new moreObj({ 
  12.             fullscreen : true
  13.             scroll : 'vertical' 
  14.         }); 
  15.   
  16.     } 
  17. }); 

完成初始化Panel组件后,界面将存在一个Panel的UI,此时并没有任何内容,现在添加一个list以便显示更多数据列表。在initComponent初始化函数内增加以下一段Ext.list代码:

  1. this.list5 = new Ext.List({ 
  2.       itemTpl: '<tpl if="needsIcon"><img width="26" height="26" src="images/{icon}.jpg" align="absmiddle"  /></tpl>{name}', 
  3.       store: new Ext.data.Store({ 
  4.              fields: ['name','icon','needsIcon'], 
  5.              data: [ 
  6.                     {"name" : "直接登录","icon":'login',"needsIcon":true}, 
  7.                     {"name" : "找回密码","icon":'password',"needsIcon":true}, 
  8.                     {"name" : "声音提示","icon":'sound',"needsIcon":true}, 
  9.                     {"name" : "关于我们","icon":'version',"needsIcon":false}, 
  10.                     {"name" : "问题反馈","icon":'question',"needsIcon":true}, 
  11.                     {"name" : "客服电话","icon":'phone',"needsIcon":true}, 
  12.                     {"name" : "软件版本0.92","icon":'version',"needsIcon":true} 
  13.              ] 
  14.         }), 
  15.         title: 'title1' 
  16. }); 

完成list的初始化后,将list加入到外部Panel中,在initComponent增加如下代码:

  1. this.listpanel = new Ext.Panel({ 
  2.        title: '更多'
  3.        items: [this.list5] 
  4. }) 
  5. this.items = [this.listpanel]; 

 此时大部分sencha代码都基本完毕,效果如下图:

相信大家都看到此时的界面仍然不是我们所想要的微博更多界面,那我们现在开始对该list界面进行修饰一翻,在初始化Ext.list内部增加以下几个属性:

  1. ui: 'round'
  2. scroll : false
  3. margin : '10 15 10 15' 

 

增加属性margin是为了list的数据和上下左右的边框距离远一点,以便更好展示按钮效果。

接着,在html5页面上增加一个css文件,以便对list的ui进行定制,如下导入css文件:

  1. <link href="test.css" rel="stylesheet"  /> 

 

在sencha.js里面的list组件增加两个css属性,如下代码:

  1. cls : 'list2'
  2. itemCls : 'list2_item'

 

第一个cls为list组件的class属性,第二个为list组件的每个数据项各自的class属性

最后在test.css文件内增加以下css代码,以便修正每个数据项的位置以及风格:

  1. .list2{ 
  2.     -webkit-border-radius : 10px; 
  3.   
  4. .list2 .x-list-item{ 
  5.     background-color : #FFF; 
  6.     border:1px solid silver; 
  7.     -webkit-border-radius : 10px; 
  8.   
  9. .list2 .x-list-item:first-of-type{ 
  10.     margin : 0 0 15px 0; 
  11.     border-top:1px solid silver; 
  12. .list2 .x-list-item:nth-of-type(2){ 
  13.     -webkit-border-bottom-left-radius:0px; 
  14.     -webkit-border-bottom-right-radius:0px; 
  15. .list2 .x-list-item:nth-of-type(3){ 
  16.     border-top:0px; 
  17.     margin : 0 0 15px 0; 
  18.     -webkit-border-top-left-radius:0px; 
  19.     -webkit-border-top-right-radius:0px; 
  20. .list2 .x-list-item:nth-of-type(4){ 
  21.     -webkit-border-bottom-left-radius:0px; 
  22.     -webkit-border-bottom-right-radius:0px; 
  23. .list2 .x-list-item:nth-of-type(5){ 
  24.     border-top:0px; 
  25.     -webkit-border-radius:0px; 
  26. .list2 .x-list-item:nth-of-type(6){ 
  27.     border-top:0px; 
  28.     margin : 0 0 15px 0; 
  29.     -webkit-border-top-left-radius:0px; 
  30.     -webkit-border-top-right-radius:0px; 
  31. .list2 .x-list-item:nth-of-type(7){ 
  32.     margin : 0 0 15px 0; 
  33.   
  34. .list2 .x-item-selected:last-child{ 
  35.     -webkit-border-bottom-left-radius:10px; 
  36.     -webkit-border-bottom-right-radius:10px; 
  37. .list2 .x-item-selected:first-of-type{ 
  38.     -webkit-border-top-left-radius:10px; 
  39.     -webkit-border-top-right-radius:10px; 
  40.   
  41. .list2 img{ 
  42.     margin-right:10px; 

此处的css更多的是利用radius属性对每个选项的的四个角进行圆角效果,由于list的每个数据项都需要分组,css里面则采用nth-of-type等选择符自定义分组,因此存在一定的局限性。

此时代码已经基本完成。效果图如下:

center

这样,iPhone微博更多UI界面已经制作完成。目前对于此解决方案,存在一种局限性,list数据需固定、分组需固定,暂时无法做到数据的实时性等功能。

 

 

 

责任编辑:佚名 来源: imsankyu
相关推荐

2013-05-27 09:52:35

Android开发移动开发移动应用

2011-09-02 15:18:49

Sencha Touc

2011-07-26 10:44:15

Sencha Touc

2011-07-26 10:21:25

Sencha Touc

2011-07-25 16:21:22

Sencha touc

2011-08-15 09:51:45

Sencha TouciPad

2011-09-05 11:23:26

EclipseSencha Touc框架

2011-07-25 15:55:21

Sencha ToucHtml 5

2013-07-10 14:15:38

php新浪微博

2011-07-26 09:41:50

Sencha Touc特性HTML 5

2010-11-22 10:31:17

Sencha touc

2011-09-05 11:27:17

Sencha Touc框架HTML5

2011-09-02 16:42:51

Sencha ToucWeb应用

2011-07-26 09:46:53

Sencha Touc

2013-07-01 18:34:47

个推案例新浪微博

2015-01-21 15:28:16

Android源码新浪微博

2011-12-08 16:10:18

2011-07-22 10:38:55

HTC新浪Facebook

2011-09-05 10:20:21

Sencha ToucAPP

2012-02-28 14:48:41

点赞
收藏

51CTO技术栈公众号