在这里插入图片描述
需求背景:
信用卡网申接入(IOS)
实现思路:
自定义cell封装CycleScrollView 可使用第三方库:
pod 'SDCycleScrollView','1.80'
原文地址
https://kunnan.blog.csdn.net/article/details/117529892
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface QCTbannerViewTableViewCell : UITableViewCell
@property (nonatomic, strong) id models;
@property (nonatomic, copy) void (^block)(id sender);
+ (instancetype) tableViewCellWithTableView:(UITableView *) tableView block:(void (^)(id sender))block models:(id) models ;
+ (instancetype) tableViewCellWithTableView:(UITableView *) tableView;
/** block方式监听点击 */
@property (nonatomic, copy) void (^clickItemOperationBlock)(NSInteger currentIndex);
@end
NS_ASSUME_NONNULL_END
//
#import "QCTbannerViewTableViewCell.h"
#import "SDCycleScrollView.h"
@interface QCTbannerViewTableViewCell ()
@property (nonatomic,weak) SDCycleScrollView *cellView;
@end
@implementation QCTbannerViewTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;//去掉选中效果
[self selfInit];
[self createSubView];
[self bindViewModel];
}
return self;
}
- (void)bindViewModel {
}
- (void)selfInit{
self.contentView.backgroundColor = kcellColor;
}
- (void)createSubView {
[self cellView];
}
static NSString *identifier = @"QCTbannerViewTableViewCell";//QCTCheckOutViewcellSection4topTableViewCell
+ (instancetype) tableViewCellWithTableView:(UITableView *) tableView{
QCTbannerViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {// ------并不会执行
cell = [[QCTbannerViewTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell;
}
+ (instancetype) tableViewCellWithTableView:(UITableView *) tableView block:(void (^)(id sender))block models:(id) models {
QCTbannerViewTableViewCell *cell = [self tableViewCellWithTableView:tableView];
if (block) {
cell.block = block;
}
cell.models = models;
return cell;
}
#pragma mark - ******** model
- (void)setModels:( id)models{
_models =models;
self.cellView.localizationImageNamesGroup = models;
}
- (SDCycleScrollView *)cellView{
if (nil == _cellView) {
SDCycleScrollView *tmpView = [[SDCycleScrollView alloc]init];
_cellView = tmpView;
_cellView.autoScrollTimeInterval = 3.0;
_cellView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_cellView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
_cellView.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
[tmpView setBackgroundColor:kcellColor];
[self.contentView addSubview:_cellView];
__weak __typeof__(self) weakSelf = self;
[_cellView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.contentView).offset(kAdjustRatio(15));
make.right.equalTo(weakSelf.contentView).offset(- kAdjustRatio(15));
make.top.equalTo(weakSelf.contentView).offset(kAdjustRatio(0));
make.height.mas_equalTo(kAdjustRatio(150));
make.bottom.equalTo(weakSelf.contentView).offset(kAdjustRatio(0));
}];
//监听点击
// __weak __typeof__(self) weakSelf = self;
[_cellView setClickItemOperationBlock:^(NSInteger currentIndex) {
if(weakSelf.clickItemOperationBlock){
weakSelf.clickItemOperationBlock(currentIndex);
}
}];
}
return _cellView;
}
- (void)layoutSubviews {
[super layoutSubviews];
UIView *view = self.cellView;
[view layoutIfNeeded];
view.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0];//设置阴影的颜色
view.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.16].CGColor;
view.layer.shadowOffset = CGSizeMake(0,2);//设置阴影的偏移量,阴影的大小,x往右和y往下是正
view.layer.shadowRadius = 3;
view.layer.shadowOpacity = 1;//设置阴影的透明度
view.layer.cornerRadius = 10;
view.clipsToBounds = YES;//Setting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO.
}
@end
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有