ios-Application Management dictionary to model

Source: Internet
Author: User

Added an app class two files app.m app.h

app.m

////app.m//Application Management////Created by Yaguangzhu on 15/7/31.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "App.h"@implementationapp-(APP *) Initwithdict: (Nsdictionary *) dict{if(self =[Super Init]) {Self.miaoshu= dict[@"Miaoshu"]; Self.icon= dict[@"icon"]; }    returnSelf ;}+ (APP *) Appwithdict: (Nsdictionary *) dict{return[Self alloc] initwithdict:dict];}@end

App.h

////App.h//Application Management////Created by Yaguangzhu on 15/7/31.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<Foundation/Foundation.h>@interfaceApp:nsobject@property (nonatomic,copy) NSString*Miaoshu, @property (nonatomic,copy) NSString*icon;-(APP *) Initwithdict: (Nsdictionary *) dict;+ (APP *) Appwithdict: (Nsdictionary *) dict;@end
////VIEWCONTROLLER.M//Application Management////Created by Yaguangzhu on 15/7/31.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"#import "App.h"@interfaceViewcontroller () @property (nonatomic,strong) Nsarray*apps;@end@implementationViewcontroller-(Nsarray *) apps{if(_apps = =Nil) {NSString*path = [[NSBundle mainbundle] Pathforresource:@"app.plist"Oftype:nil]; Nsarray*array =[Nsarray Arraywithcontentsoffile:path]; Nsmutablearray*arraymodels =[Nsmutablearray array];  for(Nsdictionary *dictinchArray) { app *model = [app appwithdict:dict]; //Model.miaoshu = dict[@ "Miaoshu"]; //Model.icon = dict[@ "icon"];[Arraymodels Addobject:model]; } _apps=Arraymodels; }        return_apps; }- (void) viewdidload {[Super viewdidload]; intColums =3; CGFloat viewwidth=Self.view.frame.size.width; CGFloat APPW= the; CGFloat APPH= -; CGFloat margintop= -; CGFloat Maginx= (VIEWWIDTH-COLUMS*APPW)/(colums+1); CGFloat Maginy=Maginx;  for(intI=0; i<self.apps.count;i++)//9 = Self.apps.count{app*appmodel =Self.apps[i]; UIView*appview =[[UIView alloc] init]; //Appview.backgroundcolor = [Uicolor redcolor];        intColidx = i%colums; intRowidx = I/colums; CGFloat AppX= maginx+ Colidx * (APPW +Maginx); CGFloat Appy= MarginTop +rowidx * (APPH +maginy); Appview.frame=CGRectMake (AppX, Appy, APPW, APPH);        [Self.view Addsubview:appview]; //Adding child controlsUiimageview *imgviewicon =[[Uiimageview alloc]init]; //Imgviewicon.backgroundcolor = [Uicolor bluecolor];CGFloat iconw = $; CGFloat Iconh= $; CGFloat IconX= (APPVIEW.FRAME.SIZE.WIDTH-ICONW) *0.5; CGFloat Icony=0; Imgviewicon.frame=CGRectMake (IconX, Icony, Iconw, Iconh);        [Appview Addsubview:imgviewicon]; Imgviewicon.image=[UIImage ImageNamed:appModel.icon]; UILabel*lblname =[[UILabel alloc] init]; //Lblname.backgroundcolor = [Uicolor yellowcolor];CGFloat Namew =Appview.frame.size.width; CGFloat Nameh= -; CGFloat Namey=Iconh; CGFloat NameX=0; Lblname.frame=CGRectMake (NameX, Namey, Namew, Nameh);                [Appview Addsubview:lblname]; UIButton*btndowload =[[UIButton alloc] init]; Btndowload.backgroundcolor=[Uicolor Blackcolor]; Lblname.text=Appmodel.miaoshu; Lblname.font= [Uifont systemfontofsize: -]; Lblname.textalignment=Nstextalignmentcenter; CGFloat BTNW=iconw; CGFloat BTNH= -; CGFloat btnx=IconX; //cgfloat Btny = Namey + Nameh;CGFloat Btny =Cgrectgetmaxy (lblname.frame); Btndowload.frame=CGRectMake (btnx, Btny, BTNW, BTNH);        [Appview Addsubview:btndowload]; [Btndowload settitle:@"Xia Zai"Forstate:uicontrolstatenormal]; [Btndowload settitle:@"Finsh"forstate:uicontrolstatehighlighted]; [Btndowload setbackgroundimage:[uiimage imagenamed:@" A"] Forstate:uicontrolstatenormal]; [Btndowload setbackgroundimage:[uiimage imagenamed:@"Ten"] forstate:uicontrolstatehighlighted]; BtnDowload.titleLabel.font= [Uifont systemfontofsize: -]; //button's Click event[Btndowload addtarget:self Action: @selector (Btndownclick) forcontrolevents:uicontroleventtouchupinside]; }        }- (void) btndownclick{NSLog (@"ssss");}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

ios-Application Management dictionary to model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.