簡體   English   中英

如何為UICollectionViewCell使用UITableViewCellAccessoryCheckmark單元格樣式

[英]How to use UITableViewCellAccessoryCheckmark cell styles for UICollectionViewCell

我正在使用UICollectionView方法,目前將設備照片集成到UICollectionViewCells中。 我想為UICollectionViewCells添加單元格樣式方法。

是否有可用於UICollectionView的任何單元格樣式(如UITableViewCellAccessoryCheckmark

您可以創建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;
    }

這只是一個想法。 您可以將其他子視圖添加到集合視圖單元格。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM