InterfaceViewcontroller ()/** get. plist data*/@property (nonatomic,strong) Nsarray*APs;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //total columns of nine Gongge inttotalcolumns=5; //size of 1.1 squaresCGFloat appw= -; CGFloat APPH= -; //2. Calculate clearance = (width of controller view -5* application width)/application width +1CGFloat marginx= (SELF.VIEW.FRAME.SIZE.WIDTH-TOTALCOLUMNS*APPW)/(totalcolumns+1); CGFloat Marginy= -; //3. The number of applications to create the corresponding lattice for(intindex=0; index<self.aps.count; index++) {NSBundle*bundle=[NSBundle Mainbundle]; // Read the Xib file (creates Appsview.All of the objects described in Xib. and return in the array in order)
Nsarray *objs=[bundle loadnibnamed:@ "appsview" Owner:nil Options:nil];
UIView *appview=[Objs lastobject];
//Add View
[Self.view Addsubview:appview];
//Set Frame
introw=index/Totalcolumns;intcol=index%Totalcolumns;
//calculate x and yCGFloat appx=marginx+col* (appw+Marginx);
CGFloat Appy=marginy+row * (APPH +marginy);
Appview.frame=CGRectMake (appx, Appy, APPW, APPH);
//Setting up data
Apps *app=Self.aps[index];
// Set the picture (Appview in Xib Uiimageview of the child control)
// Uiimageview *iconview=appview.subviews[0]; // Mode 1
Uiimageview *iconview= (Uiimageview *) [Appview Viewwithtag:ten]; // Mode 2
iconview.image= [UIImage ImageNamed:app.icon];
// Set name (Appview child control in Xib UILabel)
// UILabel *namelabel=appview.subviews[1]; // Mode 1
UILabel *namelabel= (UILabel *) [Appview Viewwithtag:]; // Mode 2
namelabel.text= App.name;
}
}
IOS reads child controls in the Xib