我正在使用UICollectionView
方法,现在当前在UICollectionViewCells中集成了设备照片。我想为UICollectionViewCells添加单元格样式方法。
是否有任何可用于UICollectionView的单元格样式,如UITableViewCellAccessoryCheckmark
?
答案 0 :(得分:0)
您可以创建UICollectionViewCell类并初始化要在单元格中显示的内容,如
CollectionViewCustomCell.h
#import <UIKit/UIKit.h>
@interface CollectionViewCustomCell : UICollectionViewCell
@property (retain, nonatomic) UILabel* label;
@property (retain, nonatomic) UIImageView *myImageView;
@end
#import "CollectionViewCustomCell.m"
@implementation CollectionViewCustomCell
@synthesize label,myImageView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.font = [UIFont boldSystemFontOfSize:35.0];
label.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:label];;
myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];
myImageView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:myImageView];
}
return self;
}
@end
您正在将集合视图初始化,将集合视图注册到CollectionViewCustomCell
[_collectionView registerClass:[CollectionViewCustomCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
并在cellForItemAtIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCustomCell *customcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
customcell.label.text = @"Text";
customcell. myImageView.image = yourImage;
return customcell;
}
这只是一个想法。您可以将其他子视图添加到集合视图单元格。