github:https://github.com/potato512/SYDemo_Masonry
UICollectionView视图结合masonry适配的使用。
UICollectionView视图中,使用了自定义header页眉视图、footer页脚视图,以及自定义的cell单元格视图。
效果图
代码示例(包含自定义header、footer、cell,以及model)
1、自定义header页眉视图
#import <UIKit/UIKit.h>
static NSString *const identifierCollectionHeader = @"CollectionHeaderView";
static CGFloat const heightCollectionHeader = 40.0;
@interface CollectionHeaderView : UICollectionReusableView
@property (nonatomic, strong) UILabel *titleLabel;
@end
#import "CollectionHeaderView.h"
@implementation CollectionHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor greenColor];
[self setUI];
}
return self;
}
#pragma mark - 视图
- (void)setUI
{
self.titleLabel = [[UILabel alloc] init];
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.bottom.mas_equalTo(0);
make.left.mas_equalTo(10.0);
make.right.mas_equalTo(-10.0);
}];
self.titleLabel.textAlign