「这是我参与2022首次更文挑战的第16天,活动详情查看:2022首次更文挑战」。
引言
需求背景:
信用卡网申接入(IOS)
实现思路:
自定义cell封装CycleScrollView 可使用第三方库:
pod 'SDCycleScrollView','1.80'
I 自定义cell封装CycleScrollView
1.1 cell 头文件
#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
1.2 cell 实现文件
//
#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
1.3 cell的使用
- 构建数据模型
NSArray *imageNames =
@[@"img_jinrong_ad1",
@"img_jinrong_ad2",
// @"banner03",
];
self.viewModel.picDataArray = imageNames;
- cell的初始化
case CRMFinSupermarketViewSection4Banner:
{
QCTbannerViewTableViewCell *cell = [QCTbannerViewTableViewCell tableViewCellWithTableView:tableView block:^(id _Nonnull sender) {
} models:self.viewModel.picDataArray];
// 处理cell的点击事件
// if(self.viewModel.clickItemOperationBlock){
//
// cell.clickItemOperationBlock = self.viewModel.clickItemOperationBlock;
//
//
//
// }
return cell;
//
}
break;
II 广告弹窗(支持显示动画及调整广告比例)
从CSDN下载Demo : https://download.csdn.net/download/u011018979/16591848
1、原文地址:blog.csdn.net/z929118967/…
2、应用场景: 打开app时弹出广告
3、效果图: 按照图片实际大小显示
采用Masonry进行界面布局,按照比例显示图片。
see also
更多内容请关注 #小程序:iOS逆向,只为你呈现有价值的信息,专注于移动端技术研究领域;