Ios 用于性能优化的自定义图形UICollectionViewCell子视图

Ios 用于性能优化的自定义图形UICollectionViewCell子视图,ios,objective-c,xcode,drawrect,uicollectionviewcell,Ios,Objective C,Xcode,Drawrect,Uicollectionviewcell,在我的UICollectionViewCell子类中,我有以下代码来布局我想要的子视图: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, 10, 190, 40)]; _titleLabel.font = [UI

在我的UICollectionViewCell子类中,我有以下代码来布局我想要的子视图:

 - (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, 10, 190, 40)];
        _titleLabel.font = [UIFont boldFlatFontOfSize:22];
        _titleLabel.backgroundColor = [UIColor clearColor];

        _fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, 35, 190, 30)];
        _fromLabel.font = [UIFont flatFontOfSize:14];
        _fromLabel.backgroundColor = [UIColor clearColor];


        UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 90, 90)];
        containerView.backgroundColor = [[UIColor colorWithPatternImage:[UIImage imageNamed:@"cream_pixels"]] colorWithAlphaComponent:0.8];
        [self.contentView addSubview:containerView];

        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        [_iconView setCenter:containerView.center];
        _iconView.backgroundColor = [UIColor whiteColor];
        _iconView.contentMode = UIViewContentModeScaleAspectFit;
        _iconView.image = [UIImage imageNamed:@"envelopeIcon.png"];
        _iconView.backgroundColor = [UIColor clearColor];
        [containerView addSubview:_iconView];

        _dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, self.contentView.frame.size.height - 23, self.contentView.frame.size.width-97, 25)];
        [_dateLabel setBackgroundColor:[UIColor clearColor]];
        [_dateLabel setFont:[UIFont boldFlatFontOfSize:13]];
        [_dateLabel setTextColor:[[UIColor wetAsphaltColor] colorWithAlphaComponent:0.6f]];
        [_dateLabel setTextAlignment:NSTextAlignmentLeft];
        [_dateLabel setLineBreakMode:NSLineBreakByCharWrapping];
        [_dateLabel setNumberOfLines:0];

        _typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.f, 0.f , 4, self.contentView.frame.size.height)];
        _typeLabel.layer.cornerRadius = 0.f;
        _typeLabel.backgroundColor = [UIColor belizeHoleColor];

        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_fromLabel];
        [self.contentView addSubview:_typeLabel];
        [self.contentView addSubview:_dateLabel];

        self.backgroundColor = [[UIColor cloudsColor] colorWithAlphaComponent:1.f];
        self.layer.cornerRadius = 3.2f;

        self.layer.masksToBounds = NO;
        self.layer.contentsScale = [UIScreen mainScreen].scale;
        self.layer.borderColor = [[UIColor silverColor] colorWithAlphaComponent:0.2].CGColor;
        self.layer.borderWidth = 0.5f;
        self.layer.shadowOpacity = 0.35f;
        self.layer.shadowRadius = 3.f;
        self.layer.shadowOffset = CGSizeMake(0, 3.f);
        self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
        self.layer.shouldRasterize = YES;

        [_titleLabel setText:@"Nuevo Mensaje"];
    }
    return self;
}
我知道,为了提高性能,建议使用自定义图形将子视图添加到单元中,而不是通过对其内容进行分层


我怎样才能做到这一点

我认为你的理解是错误的。不能通过图形添加标签或图像视图。像您这样添加它们是正确的方法。@rdelmar那么,Twitter for iOS与UITableViewCells一起使用的技术不适用于UICollectionViewCells?我不知道Twitter for iOS使用什么。你…吗?你看过他们的代码吗?我指的是()技术。