五分鐘,運用cocoaui庫,搭建主流iOS app中我的介面,cocoauiios

來源:互聯網
上載者:User

五分鐘,運用cocoaui庫,搭建主流iOS app中我的介面,cocoauiios

  本項目基於天天團購項目,在上一篇中有說到!

  首先介紹一些cocoaui,是國內的一名程式員做的開源的開源系統,目的是為了簡化ios布局!官網地址:www.cocoaui.com,github地址:https://github.com/ideawu/cocoaui

  我們這裡使用xml定義布局介面,其實就是傳統的html + css定義介面,大部分人都有網頁布局的經驗,搞ios布局還是很容易入手並且快捷的!我們首先看下我們要做的介面:

  

  我們按照html+css的格式來定義這個介面:  

<div>    <style>        .headDiv        {        width:100%;        }                .divStyle{        width:100%;        height:auto;        border-bottom: 1 solid #eee;        background:#fff;        vertical-align:middle;        }                .subdivStyle        {        height:auto;        border: 1 solid #eee;        height:40px;        background:#fff;        }                        .textStyle{        float:left;        height:40px;        valign:middle;        }                .btnStyle        {        background:#EDA67B;        width:80%;        height:50px;        float:center;        }            </style>        <div id="headContent" class="headDiv">        <img id="profileHeader" style="width:80px;height:80px;float:center;margin:10px;" src="default_head.png" />    </div>        <div id="myWashCar" class="subdivStyle" style="width:50%;height:80px;">        <img style="margin:10px;width:50px;height:50px;valign:middle;" src="ic_mt_coupon" />        <span type="text" class="textStyle" >消費卷</span>    </div>    <div id="myCoupon" class="subdivStyle" style="width:100%;height:80px;">        <img style="margin:10px;width:50px;height:50px;valign:middle" src="ic_user_main_favorite.png" />        <span class="textStyle" style="vertical-align:middle;" >我的收藏</span>    </div>        <div id="myCar" class="divStyle">        <img style="margin:10px" src="myfollow.png" />        <span type="text" class="textStyle">我的訂單</span>        <img style="float:right;margin:10px;" src="ic_arrow.png" />    </div>            <div id="myMsg" class="divStyle">        <img style="margin:10px" src="mylike.png" />        <span class="textStyle">我的評價</span>        <img style="float:right;margin:10px;" src="ic_arrow.png" />    </div>    <div id="myVersion" class="divStyle">        <img style="margin:10px" src="moreitems_version.png" />        <span type="text" class="textStyle">版本更新</span>        <img style="float:right;margin:10px;" src="ic_arrow.png" />    </div>        </div>

  將其命名為profile.xml檔案放到工程中。格式是不是和普通的html+css介面一模樣!支援大部分的html標記和css屬性!

  然後在ProfileViewController中引入profile.xml檔案:代碼如下:

- (void)viewDidLoad{    [super viewDidLoad];        [self initSystemBtn];            root = [IView namedView:@"profile.xml"];    [self addIViewRow:root];    [self reload];            [self initEvent];}

  點擊頭像需要進入修改玩家資訊介面,需要監聽頭像的點擊事件:

-(void)initEvent{    __weak typeof(self) me = self;    IImage *profileHeader = (IImage *)[root getViewById:@"profileHeader"];    [profileHeader addEvent:IEventClick handler:^(IEventType type,IView *view){        [me gotoProfileEdit];    }];}

   是不是很簡單就能定義一個介面!

  補充

  1:對SdWebImage的支援,IImage(UIImageView的再次封裝)中暴露了UIIMageView的介面,可以方便的使用sdWebImage,開始是不支援的,和作者溝通了一下,暴露了這個介面!

  2:對上拉重新整理和下拉載入的支援。有例子為證:http://www.cocoaui.com/docs/api/IRefreshControl

  3: 對於webview的支援!控制項中沒有對於webview的支援,如果頁面中需要嵌入webview則需要動態建立!

  4:對於radio和checkbox的支援,目前還不支援,需要動態建立,不過非常easy!

  5: 由於很多app 都需要端,xml檔案布局可以直接移植到移動端下面!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.