IOS reads child controls in the Xib

Source: Internet
Author: User

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

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.