IOS 用代码配置启动页

1,xcode版本10.1,首先在LaunchScreen.storyboard上设置一下StoryBoard ID 如图


2,在APPDelegate.m中增加属性:@property (strong, nonatomic) UIView *launchView;

3,在- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions;中调用下面方法

-(void)setLaunchImg{

    UIViewController *viewController = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil] instantiateViewControllerWithIdentifier:@"LaunchScreen"];

    self.launchView= viewController.view;

    self.launchView.frame = CGRectMake(0, 0, self.window.screen.bounds.size.width, self.window.screen.bounds.size.height);

    [self.window addSubview:self.launchView];

    UIImageView*imageV = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.launchView.frame.size.width,self.launchView.frame.size.height)];

    [imageVsetImage:[UIImageimageNamed:@"logo.jpeg"]];

    imageV.contentMode = UIViewContentModeScaleAspectFill;

    [self.launchViewaddSubview:imageV];

    [self.window bringSubviewToFront:self.launchView];

//可以设置启动页的存在时间

    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(removeLun) userInfo:nil repeats:NO];

}

-(void)removeLun

{

    [self.launchView removeFromSuperview];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容