广告图的添加
问题描述:在启动图上添加不固定文字(网络请求获取的),或者广告图。
-
直接上一帧未✂️ oh yeah 版的效果图吧!
解决办法
<span id = "No.1">1. 自己建立一个AdvertisementViewController,在AdvertisementViewController
里实现自己想要效果,例如添加背景图片 && logo && 展示文字的Label等,viewdidload中调用adStart代码如下:
- (void)adStart {
// 背景图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
imageView.image = [UIImage imageNamed:@"launchpage_BackgroundImage"];
[self.view addSubview:imageView];
// 添加Logo
UIImage *logoIm = [UIImage imageNamed:@"launchpage_logo"];
CGFloat logoImWidth = logoIm.size.width;
CGFloat logImHeight = logoIm.size.height;
UIImageView *logoIV = [[UIImageView alloc] initWithFrame:CGRectMake((FrameW - logoImWidth)/2, FrameH - 84/2*WidthScale375 - logImHeight, logoImWidth, logImHeight)];
logoIV.image = logoIm;
[self.view addSubview:logoIV];
// 添加label
UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(5, FrameH - 15 - 40/2*WidthScale375, FrameW - 10, 15)];
lab.text = @"要展示的文字";
lab.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:lab];
// 初始化定时器
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(adChangeNextViewController) userInfo:nil repeats:NO];
}
/** 定时展示完页面后触发方法 */
- (void)adChangeNextViewController {
[((AppDelegate *)([UIApplication sharedApplication].delegate)) showNextViewController];
}
2. 修改appDelegate
(1) appDelegate.h中暴露方法
/** 模拟启动页回来调用的方法 */
- (void)showNextViewController;
(2)appDelegate.m 在didFinishLaunchingWithOptions
方法中进行相关更改
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 模拟启动页
AdvertisementViewController *StartFigure = [[AdvertisementViewController alloc] init];
self.window.rootViewController = StartFigure;
[self.window makeKeyAndVisible];
return YES;
}
/** 模拟启动页回来调用的方法 */
- (void)showNextViewController {
// 模拟启动图结束了,跳这里,这里面正常处理,例如:改走引导页,或者TabBarController或者登录页面等等,自己决定啦。。。
self.window.rootViewController= 引导页/TabBarController/登录页面;
}