我正在尝试让你的标签和图片显示在集合视图单元格中,但只有图像才会出现在我的代码中
标题文件
#import <UIKit/UIKit.h>
#import "ComicMetadata.h"
@interface ComicCell : UICollectionViewCell
@property (nonatomic, retain) UIImageView *page;
@property (nonatomic, retain) UILabel *name;
@end
身体
#import "ComicCell.h"
@implementation ComicCell
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self){
self.page = [[UIImageView alloc] init];
self.name = [[UILabel alloc] initWithFrame:self.bounds];
self.autoresizesSubviews = YES;
self.name.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.name.font = [UIFont systemFontOfSize:13];
self.name.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:self.page];
[self.contentView addSubview:self.name];
self.name.text = @"Test";
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
//self.page.frame = self.contentView.bounds;
self.page.frame = CGRectMake(0, 0, 234, 312);
}
我做错了什么?额外的文本,因为Stackoverflow不喜欢代码与文本的比率
答案 0 :(得分:0)
当带有框架的ComicCell初始化时,边界不会完全初始化,您必须在layoutSubviews中再次为标签设置框架。
- (void)layoutSubviews{
[super layoutSubviews];
self.page.frame = CGRectMake(0, 0, 234, 312);
self.name.frame = CGRectMake(0, 0, 234, 312);
}