In IOS, the app implements the jiugongge feature, and in IOS, the app implements the jiugongge feature.

Source: Internet
Author: User

In IOS, the app implements the jiugongge feature, and in IOS, the app implements the jiugongge feature.

The idea of implementing the jiugongge algorithm is as follows:

 

Example:

1 // 2 // ViewController. m 3 // jiugongge 4 // 5 // Created by Li Qianwei on 15/3/26. 6 // Copyright (c) Future of Lee in 2015. all rights reserved. 7 // 8 9 # import "ViewController. h "10 11 @ interface ViewController () 12 13 @ property (nonatomic, strong) NSArray * data; 14 @ end15 16 @ implementation ViewController17 18-(NSArray *) data {19 if (_ data = nil) {20 NSString * fileName = [[NSBundle mainBundle] pathForResource: @ "app. plist "ofType: nil]; 21 _ data = [NSArray arrayWithContentsOfFile: fileName]; 22} 23 24 return _ data; 25} 26 27-(void) viewDidLoad {28 [super viewDidLoad]; 29 30 int colNumber = 3; 31 32 CGFloat appW = 85; 33 CGFloat appH = 90; 34 35 36 CGFloat Margat values = (self. view. frame. size. width-appW * colNumber)/(colNumber + 1); 37 CGFloat marginY = 15; 38 39 for (int index = 0; index <self. data. count; index ++) {40 int row = index/colNumber; 41 int col = index % colNumber; 42 CGFloat appX = col * (appW + Margat) + marginX; 43 CGFloat appY = row * (appH + marginY) + 30; 44 UIView * appView = [[UIView alloc] init]; 45 // appView. backgroundColor = [UIColor greenColor]; 46 appView. frame = CGRectMake (appX, appY, appW, appH); 47 [self. view addSubview: appView]; 48 49 NSDictionary * dataDic = self. data [index]; 50 UIImageView * iconImg = [[UIImageView alloc] init]; 51 CGFloat iconW = 45; 52 CGFloat iconH = 45; 53 CGFloat iconX = (appW-iconW) /2; 54 CGFloat iconY = 0; 55 iconImg. frame = CGRectMake (iconX, iconY, iconW, iconH); 56 iconImg. image = [UIImage imageNamed: dataDic [@ "icon"]; 57 [appView addSubview: iconImg]; 58 59 60 UILabel * label = [[UILabel alloc] init]; 61 CGFloat labelW = appW; 62 CGFloat labelH = 25; 63 CGFloat labelX = 0; 64 CGFloat labelY = iconH; 65 label. frame = CGRectMake (labelX, labelY, labelW, labelH); 66 label. text = dataDic [@ "name"]; 67 label. font = [UIFont systemFontOfSize: 13]; 68 label. textAlignment = labels; 69 [appView addSubview: label]; 70 71 UIButton * btn = [[UIButton alloc] init]; 72 CGFloat btnX = 12; 73 CGFloat btnY = labelY + labelH; 74 CGFloat btnW = appW-2 * btnX; 75 CGFloat btnH = 20; 76 btn. frame = CGRectMake (btnX, btnY, btnW, btnH); 77 [btn labels: [UIImage imageNamed: @ "buttongreen"] forState: UIControlStateNormal]; 78 [btn setBackgroundImage: [UIImage imageNamed: @ "buttongreen_highlighted"] forState: UIControlStateHighlighted]; 79 [btn setTitle: @ "Download" forState: UIControlStateNormal]; 80 btn. titleLabel. font = [UIFont systemFontOfSize: 11]; 81 [appView addSubview: btn]; 82 83} 84 85 86 87} 88 89-(void) didReceiveMemoryWarning {90 [super didreceivemorywarning]; 91 // Dispose of any resources that can be recreated.92} 93 94 @ end

 

Related Article

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.