Realization of nine Gongge algorithm ideas:
Specific examples:
1 //2 //VIEWCONTROLLER.M3 //Nine lattice4 //5 //Created by Lee's future on 15/3/26.6 //Copyright (c) 2015 Lee's future. All rights reserved.7 //8 9 #import "ViewController.h"Ten One @interfaceViewcontroller () A -@property (nonatomic,strong) Nsarray *data; - @end the - @implementationViewcontroller - --(Nsarray *) data{ + if(_data = =Nil) { -NSString *filename= [[NSBundle Mainbundle] Pathforresource:@"app.plist"Oftype:nil]; +_data =[Nsarray arraywithcontentsoffile:filename]; A } at - return_data; - } - -- (void) Viewdidload { - [Super Viewdidload]; in - intColnumber =3; to +CGFloat APPW = -; -CGFloat APPH = -; the * $CGFloat Marginx = (SELF.VIEW.FRAME.SIZE.WIDTH-APPW * colnumber)/(Colnumber +1);Panax NotoginsengCGFloat Marginy = the; - the for(intindex =0; Index < Self.data.count; index++) { + introw = index/Colnumber; A intCol = index%Colnumber; theCGFloat AppX = col * (APPW + Marginx) +Marginx; +CGFloat appy = row * (APPH + marginy) + -; -UIView *appview =[[UIView alloc] init]; $ //Appview.backgroundcolor = [Uicolor greencolor]; $Appview.frame =CGRectMake (AppX, Appy, APPW, APPH); - [Self.view Addsubview:appview]; - theNsdictionary *datadic =Self.data[index]; -Uiimageview *iconimg =[[Uiimageview alloc] init];WuyiCGFloat iconw = $; theCGFloat Iconh = $; -CGFloat iconx= (APPW-ICONW)/2; WuCGFloat icony =0; -Iconimg.frame =CGRectMake (IconX, Icony, Iconw, iconh); AboutIconimg.image = [UIImage imagenamed:datadic[@"icon"]]; $ [Appview addsubview:iconimg]; - - -UILabel *label =[[UILabel alloc] init]; ACGFloat LABELW =APPW; +CGFloat LABELH = -; theCGFloat LabelX =0; -CGFloat labely =Iconh; $Label.frame =CGRectMake (LabelX, labely, Labelw, LABELH); theLabel.text = datadic[@"name"]; theLabel.font = [Uifont systemfontofsize: -]; theLabel.textalignment =Nstextalignmentcenter; the [Appview Addsubview:label]; - inUIButton *btn =[[UIButton alloc] init]; theCGFloat btnx = A; theCGFloat Btny = labely +Labelh; AboutCGFloat BTNW = APPW-2*btnx; theCGFloat BTNH = -; theBtn.frame =CGRectMake (btnx, Btny, BTNW, BTNH); the[Btn setbackgroundimage:[uiimage imagenamed:@"Buttongreen"] forstate:uicontrolstatenormal]; +[Btn setbackgroundimage:[uiimage imagenamed:@"buttongreen_highlighted"] forstate:uicontrolstatehighlighted]; -[BTN Settitle:@"Download"Forstate:uicontrolstatenormal]; theBtn.titleLabel.font = [Uifont systemfontofsize: One];Bayi [Appview addsubview:btn]; the the } - - the the } the the- (void) didreceivememorywarning { - [Super didreceivememorywarning]; the //Dispose of any resources the can be recreated. the } the 94 @end
Later, you can turn the dictionary into a model, and encapsulate the code.
Nine Gongge implemented in iOS