国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

IOS中實現(xiàn)九宮格

2019-11-14 19:21:33
字體:
供稿:網(wǎng)友

實現(xiàn)九宮格的算法思路:

 

具體示例:

 1 // 2 //  ViewController.m 3 //  九宮格 4 // 5 //  Created by 李前途 on 15/3/26. 6 //  Copyright (c) 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 marginX = (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 + marginX) + 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 = NSTextAlignmentCenter;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 setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];78         [btn setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];79         [btn setTitle:@"下載" 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 didReceiveMemoryWarning];91     // Dispose of any resources that can be recreated.92 }93 94 @end

 后期可將字典轉(zhuǎn)模型,以及封裝代碼。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 潞城市| 西昌市| 沧州市| 邯郸市| 朝阳县| 广德县| 太白县| 开化县| 威海市| 榕江县| 那坡县| 临桂县| 明星| 富平县| 黔江区| 登封市| 曲沃县| 旺苍县| 济南市| 桃园县| 永安市| 丰顺县| 达日县| 福安市| 洪泽县| 雷州市| 博爱县| 南郑县| 孝感市| 阳江市| 随州市| 清流县| 百色市| 新丰县| 嘉祥县| 云和县| 平原县| 连平县| 达日县| 亚东县| 汕尾市|