ios 在xib 拖拽uicollectionviewcell的选中怎么添加标示
1个回答
展开全部
// Created by 张云飞 on 16/3/29.
// Copyright © 2016年 yunfeizhang. All rights reserved.
//
#import "TableViewCell.h"
#import "Masonry.h"
#define width [UIScreen mainScreen].bounds.size.width
@implementation TableViewCell
- (void)awakeFromNib {
UICollectionViewFlowLayout * layout=[UICollectionViewFlowLayout alloc];
self.collcetionview=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, width, 200) collectionViewLayout:layout];
self.collcetionview.delegate=self;
self.collcetionview.dataSource=self;
self.collcetionview.backgroundColor=[UIColor whiteColor];
[self addSubview:self.collcetionview];
[self.collcetionview registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 4;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell * cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
return cell;
}
//布局
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 20;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 10;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(120, 120);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(5, 5, 5, 5);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
@end
// Copyright © 2016年 yunfeizhang. All rights reserved.
//
#import "TableViewCell.h"
#import "Masonry.h"
#define width [UIScreen mainScreen].bounds.size.width
@implementation TableViewCell
- (void)awakeFromNib {
UICollectionViewFlowLayout * layout=[UICollectionViewFlowLayout alloc];
self.collcetionview=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, width, 200) collectionViewLayout:layout];
self.collcetionview.delegate=self;
self.collcetionview.dataSource=self;
self.collcetionview.backgroundColor=[UIColor whiteColor];
[self addSubview:self.collcetionview];
[self.collcetionview registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 4;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell * cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
return cell;
}
//布局
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 20;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 10;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(120, 120);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(5, 5, 5, 5);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
@end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询