ios--Nine Gongge layout

Source: Internet
Author: User

[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

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.