Xcode11设置广告页和launchImage设置启动页
2020-04-22 本文已影响0人
fueb
一、广告页设置
1.SceneDelegate设置window
UIWindowScene*windowScene = (UIWindowScene*)scene;
self.window= [[UIWindowalloc]initWithWindowScene:windowScene];
self.window.frame = windowScene.coordinateSpace.bounds;
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [ViewController new];
[self.window makeKeyAndVisible];
2.开发一个广告页
- (instancetype)initWithFrame:(CGRect)frame {
if(self= [superinitWithFrame:frame]) {
// 1.广告图片
_adView= [[UIImageViewalloc]initWithFrame:frame];
_adView.userInteractionEnabled = YES;
_adView.contentMode = UIViewContentModeScaleAspectFill;
_adView.clipsToBounds=YES;
// 为广告页面添加一个点击手势,跳转到广告页面
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToAd)];
[_adView addGestureRecognizer:tap];
// 2.跳过按钮
CGFloatbtnW =60;
CGFloatbtnH =30;
_countBtn= [[UIButtonalloc]initWithFrame:CGRectMake(kscreenWidth- btnW -24, btnH, btnW, btnH)];
[_countBtn addTarget:self action:@selector(removeAdvertView) forControlEvents:UIControlEventTouchUpInside];
[_countBtn setTitle:[NSString stringWithFormat:@"跳过%d", showtime] forState:UIControlStateNormal];
_countBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[_countBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_countBtn.backgroundColor = [UIColor colorWithRed:38 /255.0 green:38 /255.0 blue:38 /255.0 alpha:0.6];
_countBtn.layer.cornerRadius = 4;
[selfaddSubview:_adView];
[selfaddSubview:_countBtn];
self.backgroundColor = [UIColor redColor];
}
return self;
}
3.在SceneDelegate中判断是否需要显示广告,如果需要则初始化一个广告页直接add到window
if(isExist) {// 图片存在
AdView*advertView = [[AdViewalloc]initWithFrame:self.window.bounds];
advertView.filePath= filePath;
[advertViewshow];
[self.windowaddSubview:advertView];
}
二、启动页设置
Assets.xcassets中添加启动页图片,LaunchScreen.storyboard中添加一个ImageView设置约束铺满全屏
image image image image