-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathViewController.m
More file actions
107 lines (88 loc) · 5.76 KB
/
ViewController.m
File metadata and controls
107 lines (88 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// ViewController.m
// CollectionView的多方格算法
//
// Created by 孔伟 on 16/5/17.
// Copyright © 2016年 孔伟. All rights reserved.
//
#import "ViewController.h"
#import "KVCollectionViewLayout.h"
#import "KVCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@interface ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, KVCollectionViewLayoutDelegate>
/** 数据*/
@property (nonatomic,strong) NSArray * datas;
@end
static NSString * cellReuseIdentifier = @"cellReuseIdentifier";
static NSInteger const numOfLine = 3;
@implementation ViewController
- (NSArray *)datas {
if (_datas == nil) {
_datas = @[
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=2009e2b8aed3fd1f2909a43a004f25ce/d833c895d143ad4b7391375684025aafa50f06ec.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=e9b80b165dafa40f23c6c8dd9b64038c/562c11dfa9ec8a13f96febc4f003918fa0ecc099.jpg",
@"http://d.hiphotos.baidu.com/image/h%3D300/sign=2c6dbc7ad700baa1a52c41bb7711b9b1/0b55b319ebc4b745f0f9c680c9fc1e178a821532.jpg",
@"http://f.hiphotos.baidu.com/image/h%3D300/sign=ed553560a1efce1bf52bceca9f50f3e8/d000baa1cd11728b3aaafab4cefcc3cec2fd2ca4.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=2009e2b8aed3fd1f2909a43a004f25ce/d833c895d143ad4b7391375684025aafa50f06ec.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=e9b80b165dafa40f23c6c8dd9b64038c/562c11dfa9ec8a13f96febc4f003918fa0ecc099.jpg",
@"http://d.hiphotos.baidu.com/image/h%3D300/sign=2c6dbc7ad700baa1a52c41bb7711b9b1/0b55b319ebc4b745f0f9c680c9fc1e178a821532.jpg",
@"http://f.hiphotos.baidu.com/image/h%3D300/sign=ed553560a1efce1bf52bceca9f50f3e8/d000baa1cd11728b3aaafab4cefcc3cec2fd2ca4.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=2009e2b8aed3fd1f2909a43a004f25ce/d833c895d143ad4b7391375684025aafa50f06ec.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=e9b80b165dafa40f23c6c8dd9b64038c/562c11dfa9ec8a13f96febc4f003918fa0ecc099.jpg",
@"http://d.hiphotos.baidu.com/image/h%3D300/sign=2c6dbc7ad700baa1a52c41bb7711b9b1/0b55b319ebc4b745f0f9c680c9fc1e178a821532.jpg",
@"http://f.hiphotos.baidu.com/image/h%3D300/sign=ed553560a1efce1bf52bceca9f50f3e8/d000baa1cd11728b3aaafab4cefcc3cec2fd2ca4.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=2009e2b8aed3fd1f2909a43a004f25ce/d833c895d143ad4b7391375684025aafa50f06ec.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=e9b80b165dafa40f23c6c8dd9b64038c/562c11dfa9ec8a13f96febc4f003918fa0ecc099.jpg",
@"http://d.hiphotos.baidu.com/image/h%3D300/sign=2c6dbc7ad700baa1a52c41bb7711b9b1/0b55b319ebc4b745f0f9c680c9fc1e178a821532.jpg",
@"http://f.hiphotos.baidu.com/image/h%3D300/sign=ed553560a1efce1bf52bceca9f50f3e8/d000baa1cd11728b3aaafab4cefcc3cec2fd2ca4.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=2009e2b8aed3fd1f2909a43a004f25ce/d833c895d143ad4b7391375684025aafa50f06ec.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=e9b80b165dafa40f23c6c8dd9b64038c/562c11dfa9ec8a13f96febc4f003918fa0ecc099.jpg",
@"http://d.hiphotos.baidu.com/image/h%3D300/sign=2c6dbc7ad700baa1a52c41bb7711b9b1/0b55b319ebc4b745f0f9c680c9fc1e178a821532.jpg",
@"http://f.hiphotos.baidu.com/image/h%3D300/sign=ed553560a1efce1bf52bceca9f50f3e8/d000baa1cd11728b3aaafab4cefcc3cec2fd2ca4.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=2009e2b8aed3fd1f2909a43a004f25ce/d833c895d143ad4b7391375684025aafa50f06ec.jpg",
@"http://c.hiphotos.baidu.com/image/h%3D300/sign=e9b80b165dafa40f23c6c8dd9b64038c/562c11dfa9ec8a13f96febc4f003918fa0ecc099.jpg",
@"http://d.hiphotos.baidu.com/image/h%3D300/sign=2c6dbc7ad700baa1a52c41bb7711b9b1/0b55b319ebc4b745f0f9c680c9fc1e178a821532.jpg",
@"http://f.hiphotos.baidu.com/image/h%3D300/sign=ed553560a1efce1bf52bceca9f50f3e8/d000baa1cd11728b3aaafab4cefcc3cec2fd2ca4.jpg",
];
}
return _datas;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.collectionView.backgroundColor = [UIColor whiteColor];
// 设置layout
KVCollectionViewLayout * layout = [[KVCollectionViewLayout alloc] init];
layout.oneMulTwoChange = 0.5;
layout.twoMulTwoChange = 0.5;
layout.delegate = self;
self.collectionView.collectionViewLayout = layout;
// 注册cell
[self.collectionView registerNib:[UINib nibWithNibName:@"KVCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:cellReuseIdentifier];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 3;
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.datas.count;
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
KVCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellReuseIdentifier forIndexPath:indexPath];
cell.label.textColor = [UIColor redColor];
cell.label.text = [NSString stringWithFormat:@" %ld", indexPath.row];
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:self.datas[indexPath.row]]];
//cell.imageView.image = [UIImage imageNamed:@"bg"];
return cell;
}
#pragma mark - KVCollectionViewLayoutDelegate
- (NSInteger)numOfItemInLine {
return numOfLine;
}
- (UIEdgeInsets)sectionInsetForSection:(NSInteger)section {
return UIEdgeInsetsMake(20, 20, 20, 20);
}
- (BOOL)isContinueLayoutForNextSection:(NSInteger)section {
return NO;
}
@end