UITableViewCell添加UICollectionView,能够左右滚动用于展示不同图片。利用UICollectionView的优点,从而性能上有很大优化

该博客介绍如何在UITableViewCell内部集成UICollectionView,利用其性能优势,创建一个可以左右滚动展示多张图片的功能。提供了Github下载链接以获取示例代码。
摘要由CSDN通过智能技术生成


Github下载地址

#import <UIKit/UIKit.h>
#import "WSCollectionViewCell.h"

@interface WSCollectionView : UICollectionView

@property (nonatomic, strong) NSIndexPath *indexPath;

@end

static NSString *CollectionViewCellIdentifier = @"CollectionViewCellIdentifier";

@interface WSTableViewCell : UITableViewCell

@property (nonatomic,strong)WSCollectionView    *collectionView;

@property (nonatomic,strong)UIImageView         *itemImageView;

@property (nonatomic,strong)UILabel             *contentLabel;

- (void)setCollectionViewDataSourceDelegate:(id<UICollectionViewDataSource, UICollectionViewDelegate>)dataSourceDelegate indexPath:(NSIndexPath *)indexPath;

- (void)configureCellWithInfo:(NSDictionary *)data;

@end


#import "WSTableViewCell.h"

@implementation WSCollectionView

@end

@implementation WSTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        [self initialize];
        
    }
    return self;
}

- (void)initialize
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    CGFloat tempImageWith = [UIScreen mainScreen].bounds.size.width / 640;
    CGFloat tempHeight = 480 * tempImageWith;
    
    self.itemImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, tempHeight)];
    self.itemImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.itemImageView.clipsToBounds = YES;
    [self.contentView addSubview:_itemImageView];
    
    self.contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, _itemImageView.frame.size.height + 10, [UIScreen mainScreen].bounds.size.width - 20, 40)];
    self.conten
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值