iOS 自定义UICollectionViewCell
来源:互联网 发布:桌面图标美化软件 编辑:程序博客网 时间:2024/05/18 14:13
@property (nonatomic,strong) UICollectionView *myCollectionView;
#pragma mark - UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
returnself.dataArray.count;
}
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
GoodCollectionViewCell * cell = [collectionViewdequeueReusableCellWithReuseIdentifier:@"ID"forIndexPath:indexPath];
cell.model =self.dataArray[indexPath.row];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
returnCGSizeMake((WIDTH-60)/2, (WIDTH-60)/2+50);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
returnUIEdgeInsetsMake(5,20, 0.01,20);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return5;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return20;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
GoodDetailViewController *gv = [[GoodDetailViewControlleralloc] init];
gv.model =self.dataArray[indexPath.row];
[self.navigationControllerpushViewController:gv animated:YES];
[collectionView reloadItemsAtIndexPaths:@[indexPath]];
}
- (UICollectionView *)myCollectionView{
if (_myCollectionView ==nil) {
UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayoutalloc]init];
layout.scrollDirection =UICollectionViewScrollDirectionVertical;
_myCollectionView = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,64, WIDTH, HEIGHT-64-49)collectionViewLayout:layout];
_myCollectionView.backgroundColor = [UIColorclearColor];
_myCollectionView.delegate =self;
_myCollectionView.dataSource =self;
[_myCollectionViewregisterClass:[GoodCollectionViewCellclass] forCellWithReuseIdentifier:@"ID"];
_myCollectionView.hidden =YES;
_myCollectionView.mj_header = [MJRefreshNormalHeaderheaderWithRefreshingTarget:selfrefreshingAction:@selector(headRefresh)];
_myCollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:selfrefreshingAction:@selector(footerRefresh)];
}
return_myCollectionView;
}
#pragma mark - 下拉刷新
- (void)headRefresh{
self.row =0;
[selfgetData];
}
- (void)footerRefresh{
self.row +=10;
[selfgetData];
}
#import <UIKit/UIKit.h>
#import "GoodModel.h"
@interface GoodCollectionViewCell :UICollectionViewCell
@property (nonatomic,strong) UIImageView *iconView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UILabel *addressLabel;
@property (nonatomic,strong) GoodModel *model;
@end
#import "GoodCollectionViewCell.h"
#import "Header.h"
# define cellW self.frame.size.width
# define cellH self.frame.size.height
@implementation GoodCollectionViewCell
@synthesize iconView,titleLabel,priceLabel,addressLabel;
- (id)initWithFrame:(CGRect)frame{
self = [superinitWithFrame:frame];
if (self) {
self.backgroundColor = [UIColorwhiteColor];
[selfcreateUI];
}
returnself;
}
- (void)createUI{
iconView = [[UIImageViewalloc] initWithFrame:CGRectMake(10,10, cellW-20,cellW-20)];
iconView.backgroundColor = [UIColorclearColor];
[self.contentViewaddSubview:iconView];
titleLabel = [[UILabelalloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(iconView.frame),cellW-20,20)];
titleLabel.textColor =selectColor;
titleLabel.font = [UIFontsystemFontOfSize:13.0f];
[self.contentViewaddSubview:titleLabel];
priceLabel = [[UILabelalloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(titleLabel.frame),cellW-20,20)];
priceLabel.textColor = [UIColorgrayColor];
priceLabel.font = [UIFontsystemFontOfSize:13.0f];
[self.contentViewaddSubview:priceLabel];
addressLabel = [[UILabelalloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(priceLabel.frame),cellW-20,20)];
addressLabel.textColor = [UIColorgrayColor];
addressLabel.font = [UIFontsystemFontOfSize:10.0f];
[self.contentViewaddSubview:addressLabel];
}
- (void)setModel:(GoodModel *)model{
_model = model;
if ([model.stateintegerValue] == 1) {
if ([StringIsNullisNotBlankString:model.image]) {
[iconViewsd_setImageWithURL:[NSURLURLWithString:model.image]placeholderImage:[UIImageimageNamed:@"chaohuitechan"]];
}else{
iconView.image = [UIImageimageNamed:@"chaohuitechan"];
}
}else{
iconView.image = [UIImageimageNamed:@"stop"];
}
titleLabel.text = [NSStringstringWithFormat:@"%@",model.title];
priceLabel.text = [NSStringstringWithFormat:@"%@元/斤",model.price];
addressLabel.text = [NSStringstringWithFormat:@"%@",model.address];
}
@end
- iOS 自定义UICollectionViewCell
- IOS自定义UICollectionViewCell(对比UITableViewCell)
- iOS UICollectionView 入门 05 创建自定义UICollectionViewCell
- IOS自定义UICollectionViewCell(对比UITableViewCell)
- Swift之自定义UICollectionViewCell
- 自定义UICollectionViewCell控件调动BUG!
- IOS菜鸟的所感所思(四)——自定义UICollectionViewCell以及网络数据的添加。
- IOS中UICollectionViewCell的问题
- iOS设置UICollectionViewCell的间距
- iOS UICollectionViewCell一些小坑
- iOS UICollectionViewCell 的 contentView 注意事项
- UICollectionViewCell
- UICollectionViewCell
- Swift自定义UICollectionViewCell不显示的解决方案
- UICollectionView学习<2>之UICollectionViewCell的自定义
- 自定义UICollectionViewCell中控件为nil
- 自定义UICollectionViewCell 以及碰到的问题
- UICollectionView和自定义UICollectionViewCell的基本用法
- 蓝桥杯校内选拔第四题
- 数字电路与逻辑设计——组合逻辑应用技巧篇
- 从零开始配置Jenkins(三)——用户权限管理
- Apache+Tomcat集群部署
- 蓝桥杯校内选拔第五题
- iOS 自定义UICollectionViewCell
- 字符串处理技巧系列1
- Git 常用命令大全最新
- 蓝桥杯校内选拔第六题
- 蓝桥杯校内选拔第七题
- 知识库--ZooKeeper + States and the Lifetime of a Session(62)
- 【Java每日一题】20161227
- 蓝桥杯校内选拔第八题
- Centos7在ifcfg文件中配置静态路由 Configuring Static Routes in ifcfg files