美文网首页
UICollectionView 自定义cell

UICollectionView 自定义cell

作者: ly_chee_ | 来源:发表于2020-06-15 10:23 被阅读0次

.h 文件内容

#import

NS_ASSUME_NONNULL_BEGIN

typedefvoid(^ButtonClick)(UIButton* sender);

@interface SquareImageCollectionCell : UICollectionViewCell

@property (nonatomic,copy) ButtonClick deleteClick;

@property (nonatomic,strong) NSString * cellImg;

@end

NS_ASSUME_NONNULL_END

.m 文件内容

#import "SquareImageCollectionCell.h"

@interface SquareImageCollectionCell()

@property (nonatomic ,strong) UIImageView *imageView;

@end

@implementation SquareImageCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {

        _imageView = [[UIImageView alloc] init];

        _imageView.layer.masksToBounds = YES;

      _imageView.layer.cornerRadius = 6.5;

      _imageView.frame = CGRectMake(0, 0,  self.contentView.frame.size.width,          self.contentView.frame.size.height);

        _imageView.contentMode = UIViewContentModeScaleAspectFill;

        [self.contentView addSubview:_imageView];

    return self;

}

-(void)setCellImg:(NSString*)cellImg{

    _imageView.image = [UIImage imageNamed:cellImg];

}

@end

相关文章

网友评论

      本文标题:UICollectionView 自定义cell

      本文链接:https://www.haomeiwen.com/subject/kflcxktx.html