UICollectionViewCell OC示例代码
时间: 2023-03-27 15:04:34 浏览: 66
以下是一个UICollectionViewCell的OC示例代码:
```
@interface MyCollectionViewCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation MyCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self setupSubviews];
}
return self;
}
- (void)setupSubviews {
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , self.bounds.size.width, self.bounds.size.height - 30)];
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
self.imageView.clipsToBounds = YES;
[self.contentView addSubview:self.imageView];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(, self.bounds.size.height - 30, self.bounds.size.width, 30)];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.font = [UIFont systemFontOfSize:14];
[self.contentView addSubview:self.titleLabel];
}
@end
```