#import "MYIHomeViewController.h"
#import "MYIHomeHeaderView.h"
#import "JFConfigFile.h"
#import "MYIHomeLayout.h"
#import "MYIHomeCell.h"
static NSString *ID = @"collectionViewCell";
@interface MYIHomeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@end
@implementation MYIHomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
//关闭自动调整滚动视图(不关闭图片轮播器会出现问题)
self.automaticallyAdjustsScrollViewInsets = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//隐藏navigationBar
self.navigationController.navigationBar.hidden = YES;
}
- (void)loadView {
[super loadView];
//添加collectionView
[self.view addSubview:self.collectionView];
}
//懒加载collectionView
- (UICollectionView *)collectionView {
if (!_collectionView) {
_collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:[[MYIHomeLayout alloc] init]];
_collectionView.backgroundColor = JFRGBColor(238, 238, 238);
//注册cell
[_collectionView registerClass:[MYIHomeCell class] forCellWithReuseIdentifier:ID];
//注册UICollectionReusableView即headerView(切记要添加headerView一定要先注册)
[_collectionView registerClass:[MYIHomeHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
_collectionView.delegate = self;
_collectionView.dataSource = self;
}
return _collectionView;
}
#pragma mark ---UICollectionViewDataSource 数据源方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 80;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MYIHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
cell.iconName = @"goodsimagetest";
cell.describe = @"蚂蚁到家蚂蚁到家蚂蚁到家";
cell.currentPrice = @"¥100";
cell.originalPrice = @"¥288";
return cell;
}
//添加headerView
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
MYIHomeHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];;
//判断上面注册的UICollectionReusableView类型
if (kind == UICollectionElementKindSectionHeader) {
return headerView;
}else {
return nil;
}
}
#pragma mark ---UICollectionViewDelegate
//设置headerView的宽高
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
return CGSizeMake(self.view.bounds.size.width, 380);
}
#pragma mark ---UICollectionViewDelegateFlowLayout
//设置collectionView的cell上、左、下、右的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(14, 0, 0, 0);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- (void)viewDidLoad {
[super viewDidLoad];
//关闭自动调整滚动视图(不关闭图片轮播器会出现问题)
self.automaticallyAdjustsScrollViewInsets = NO;
}
//注册UICollectionReusableView即headerView(切记要添加headerView一定要先注册)
[_collectionView registerClass:[MYIHomeHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
//添加headerView
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
MYIHomeHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];
//判断上面注册的UICollectionReusableView类型
if (kind == UICollectionElementKindSectionHeader) {
return headerView;
}else {
return nil;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有