BrickView是一个简单的iOS动态网格布局视图,类似于Pinterest。使用BrickView的方式类似于UITableViewDelegate和UITableViewDatasource。
该包包含了所有文档和示例,以帮助您开始。
有两种方式在项目中使用它
将BrickView/*.{h.m}
复制到您的项目中
使用CocoaPods安装,编写Podfile
platform :ios
pod 'BrickView', '~> 0.1.1'
BrickView使用一种简单的方法。它定义了一个Delegate和一个数据源,客户端进行实现。BrickViewDelegate和BrickViewDataSource类似于UITableViewDelegate和UITableViewDatasource。BrickViewDelegate具有UIScrollViewDelegate
的协议。
重置单元格并重新显示可见单元格。
- (void)reloadData;
如果BrickView没有重置可见单元格并显示新单元格,则使用updateData
。
- (void)updateData;
BrickView.h
BrickViewDataSource
和BrickViewDelegate
的方法UINib
对象与标识符,以便重用
#import "BrickView.h"
@interface ExampleViewController ()
<BrickViewDataSource, BrickViewDelegate>
@end
@implementation ExampleViewController
- (void)viewDidLoad
{
[super viewDidLoad];
BrickView *brickView = [[BrickView alloc]initWithFrame:self.view.bounds];
brickView.dataSource = self;
brickView.delegate = self;
UINib *nib = [UINib nibWithNibName:@"Cell" bundle:nil];
[self.brickView registerNib:nib forCellReuseIdentifier:@"Cell"];
[self.brickView reloadData];
}
- (CGFloat)brickView:(BrickView *)brickView heightForCellAtIndex:(NSInteger)index
{
return 100.;
}
- (NSInteger)numberOfColumnsInBrickView:(BrickView *)brickView
{
return 3;
}
- (NSInteger)numberOfCellsInBrickView:(BrickView *)brickView
{
return [self.list count];
}
- (BrickViewCell *)brickView:(BrickView *)brickView cellAtIndex:(NSInteger)index
{
static NSString *CellIdentifier = @"Cell";
BrickViewCell *cell = [brickView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = @"text";
return cell;
}
BrickView在MIT许可下可用。