Nine Gongge implemented in iOS

Source: Internet
Author: User

Realization of nine Gongge algorithm ideas:

Specific examples:

1 //2 //VIEWCONTROLLER.M3 //Nine lattice4 //5 //Created by Lee's future on 15/3/26.6 //Copyright (c) 2015 Lee's future. All rights reserved.7 //8 9 #import "ViewController.h"Ten  One @interfaceViewcontroller () A  -@property (nonatomic,strong) Nsarray *data; - @end the  - @implementationViewcontroller -  --(Nsarray *) data{ +     if(_data = =Nil) { -NSString *filename= [[NSBundle Mainbundle] Pathforresource:@"app.plist"Oftype:nil]; +_data =[Nsarray arraywithcontentsoffile:filename]; A     } at      -     return_data; - } -  -- (void) Viewdidload { - [Super Viewdidload]; in      -     intColnumber =3; to      +CGFloat APPW = -; -CGFloat APPH = -; the      *      $CGFloat Marginx = (SELF.VIEW.FRAME.SIZE.WIDTH-APPW * colnumber)/(Colnumber +1);Panax NotoginsengCGFloat Marginy = the; -      the      for(intindex =0; Index < Self.data.count; index++) { +         introw = index/Colnumber; A         intCol = index%Colnumber; theCGFloat AppX = col * (APPW + Marginx) +Marginx; +CGFloat appy = row * (APPH + marginy) + -; -UIView *appview =[[UIView alloc] init]; $ //Appview.backgroundcolor = [Uicolor greencolor]; $Appview.frame =CGRectMake (AppX, Appy, APPW, APPH); - [Self.view Addsubview:appview]; -          theNsdictionary *datadic =Self.data[index]; -Uiimageview *iconimg =[[Uiimageview alloc] init];WuyiCGFloat iconw = $; theCGFloat Iconh = $; -CGFloat iconx= (APPW-ICONW)/2; WuCGFloat icony =0; -Iconimg.frame =CGRectMake (IconX, Icony, Iconw, iconh); AboutIconimg.image = [UIImage imagenamed:datadic[@"icon"]]; $ [Appview addsubview:iconimg]; -         -          -UILabel *label =[[UILabel alloc] init]; ACGFloat LABELW =APPW; +CGFloat LABELH = -; theCGFloat LabelX =0; -CGFloat labely =Iconh; $Label.frame =CGRectMake (LabelX, labely, Labelw, LABELH); theLabel.text = datadic[@"name"]; theLabel.font = [Uifont systemfontofsize: -]; theLabel.textalignment =Nstextalignmentcenter; the [Appview Addsubview:label]; -          inUIButton *btn =[[UIButton alloc] init]; theCGFloat btnx = A; theCGFloat Btny = labely +Labelh; AboutCGFloat BTNW = APPW-2*btnx; theCGFloat BTNH = -; theBtn.frame =CGRectMake (btnx, Btny, BTNW, BTNH); the[Btn setbackgroundimage:[uiimage imagenamed:@"Buttongreen"] forstate:uicontrolstatenormal]; +[Btn setbackgroundimage:[uiimage imagenamed:@"buttongreen_highlighted"] forstate:uicontrolstatehighlighted]; -[BTN Settitle:@"Download"Forstate:uicontrolstatenormal]; theBtn.titleLabel.font = [Uifont systemfontofsize: One];Bayi [Appview addsubview:btn]; the          the     } -      -      the      the } the  the- (void) didreceivememorywarning { - [Super didreceivememorywarning]; the     //Dispose of any resources the can be recreated. the } the 94 @end

Later, you can turn the dictionary into a model, and encapsulate the code.

Nine Gongge implemented in iOS

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.