-(void) Willmovetosuperview: (UIView *) newsuperview{nsstring *path = [[NSBundle mainbundle]pathforresource:@] Books.plist "Oftype:nil"; _books = [Nsarray Arraywithcontentsoffile:path]; NSLog (@ "%@", _books); Self.frame = Newsuperview.bounds; Self.backgroundcolor = [Uicolor Redcolor]; int totalcolumns = 3; The size of the application cgfloat BOOKW = 90; CGFloat Bookh = 125; Clearance = (width of view-3 * application width)/4 cgfloat Marginx = (Self.frame.size.width-totalcolumns * bookw)/(Totalcolumns + 1); CGFloat marginy = 15; Create a corresponding box (index) for (int index = 0; index<self.books.count; index++) {//create UIView *bookview =) According to the number of applications [[UIView alloc] init]; Set background Color Bookview.backgroundcolor = [Uicolor Cyancolor]; Calculate the position of the box//Calculate line number and column number int row = Index/totalcolumns; int col = index% Totalcolumns; calculates x and y cgfloat bookx = marginx + col * (bookw + Marginx); CGFloat Booky = + Row *(Bookh + marginy); Set Frame Bookview.frame = CGRectMake (Bookx, Booky, BOOKW, Bookh); Add a frame to the Controller view [self Addsubview:bookview]; Add control//index position corresponding application information nsdictionary *bookinfo = Self.books[index]; Add picture//uiimageview *iconview = [[Uiimageview alloc] init]; UIButton * btn = [UIButton buttonwithtype:uibuttontypecustom]; [Btn setbackgroundimage:[uiimage imagenamed:bookinfo[@ "icon"] forstate:uicontrolstatenormal]; Set position cgfloat iconw = 60; CGFloat iconh = 80; CGFloat IconX = (bookw-iconw) * 0.5; CGFloat icony = 0; Btn.frame = CGRectMake (IconX, Icony, Iconw, Iconh); [Bookview ADDSUBVIEW:BTN]; Add name UILabel *namelabel = [[UILabel alloc] init]; Set position cgfloat Namew = bookw; CGFloat Nameh = 20; CGFloat NameX = 0; CGFloat Namey = Icony + iconh; Namelabel.frame = CgrectmakE (NameX, Namey, Namew, Nameh); Set Text Namelabel.text = bookinfo[@ "name"]; Set Font namelabel.font = [Uifont systemfontofsize:13]; Set Text Center alignment namelabel.textalignment = nstextalignmentcenter; [Bookview Addsubview:namelabel]; Add Download button UIButton *downloadbtn = [[UIButton alloc] init]; Set position cgfloat DOWNLOADX = 12; CGFloat Downloady = Namey + Nameh; CGFloat DOWNLOADW = bookW-2 * DOWNLOADX; CGFloat downloadh = 20; Downloadbtn.frame = CGRectMake (DOWNLOADX, Downloady, DOWNLOADW, downloadh); Set the default background UIImage *normalimage = [UIImage imagenamed:@ "Upomp_button_keyboard3"]; [Downloadbtn setbackgroundimage:normalimage Forstate:uicontrolstatenormal]; Set the highlighted background UIImage *highimage = [UIImage imagenamed:@ "upomp_button_keyboard3_highlighted"]; [Downloadbtn setbackgroundimage:highimage forstate:uicontrolstatehighlighted]; SetThe text of the button [downloadbtn settitle:@ "Download" forstate:uicontrolstatenormal]; Sets the font of the button text DownloadBtn.titleLabel.font = [Uifont systemfontofsize:13]; [Bookview ADDSUBVIEW:DOWNLOADBTN]; } }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Add an app download information module in UIView