[Self Rankwithtotalcolumns:2ANDWITHAPPW: theANDWITHAPPH: the];//Nine Gongge layout- (void) Rankwithtotalcolumns: (int) Totalcolumns ANDWITHAPPW: (int) APPW ANDWITHAPPH: (int) apph{//total number of columns int_totalcolumns =Totalcolumns; //View SizeCGFloat _APPW =APPW; CGFloat _APPH=APPH; //Transverse clearance (width of Controller view-Number of columns * application width)/(Number of columns + 1)CGFloat margin = (Self.view.frame.size.width-(_totalcolumns * the))/(_totalcolumns +1); NSLog (@"%lu", (unsignedLong) self. Titlelist.count); for(intindex =0; Index < self. Titlelist.count; index++) { //Create a small box//UIView *appview =[[UIView alloc] init]; Appview.backgroundcolor=[Uicolor Whitecolor]; AppView.layer.borderColor= [[Uicolor colorwithred:242/255.0Green242/255.0Blue242/255.0Alpha1] Cgcolor]; AppView.layer.borderWidth=1; Dataoldbody*item =[Self. Titlelist Objectatindex:index]; //Add a pictureUIButton *iconview = [[UIButton alloc] Initwithframe:cgrectmake (0,0, the, -)]; UIImage*normal =[UIImage Imagenamed:item. Charpicname]; [IconView Setbackgroundimage:normal Forstate:uicontrolstatenormal]; //Add a Click event[IconView addtarget:self Action: @selector (Handtap:) forcontrolevents:uicontroleventtouchupinside]; [IconView Settag:item. Charid]; [Appview Addsubview:iconview]; //Add introduction InformationUILabel *label =[[UILabel alloc] init]; Label.text=item. Charbodytext; Label.frame= CGRectMake (0,123, the, $); Label.font= [Uifont fontwithname:@"Kailasa"Size -]; Label.textalignment=Nstextalignmentcenter; Label.numberoflines=2; [Appview Addsubview:label]; if(moonandsuns) {Label.backgroundcolor= [Uicolor colorwithred: Wu/255.0Green Wu/255.0Blue Wu/255.0Alpha1]; Label.textcolor=[Uicolor Whitecolor]; }Else{Label.backgroundcolor=[Uicolor Whitecolor]; Label.textcolor=[Uicolor Blackcolor]; } //Create End// //calculate the position of the box ... Line number column number starting from 0//Line number introw = Index/totalcolumns;//row Number box ordinal to column number of the vendor//column number intCol = index% Totalcolumns;//column number is the ordinal of the box to the number of columns to take the remaindercgfloat AppX= margin + col * (appw + margin);//the width of each box on the left is (average interval + box own width)CGFloat appy = -+ Row * (apph + margin);//The height of each box above is the average interval + the height of the box itselfAppview.frame=CGRectMake (AppX, Appy, _APPW, _APPH); [Self.scrollview Addsubview:appview]; }}-(void) Handtap: (ID) sender{Nsinteger i=[sender tag]; NSLog (@"%ld",(Long) (i); Oldfirstbodyviewcontroller*oldfirstbody = [Self.storyboard instantiateviewcontrollerwithidentifier:@"Oldfirstbody"]; Oldfirstbody.index=i; [Self.navigationcontroller pushviewcontroller:oldfirstbody Animated:yes]; }
ios--Nine Gongge layout