iOS 启动页添加版本号

XCode中有LaunchScreen.storyboard或者LaunchScreen.xib,苹果默认使用的就是拿这个当启动页,这是一个静态的页面,也就是只能用自动布局来适配屏幕的大小,就一张图片居中显示,这个兼容性不强。另外一种方法,这种方法很多人都在用,只要设置正确 尺寸格式正确就可以正常显示的。常用的尺寸格式如下:

CA87F4BA-7F54-486B-9E8D-6B5AB1190D26.png
B1A951D8-A8A2-43AB-B8F0-2EC86F61DCEA.png
步骤如下:

1、点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image"
2、如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以及低版本的ios系统做支持.这边我选了ios8.0,ios7.0,ios6没有做支持.

55A47D57-7A6A-4DBD-91AD-B89C63CB2A8A.png

3、选择launchImage


975202FB-6791-4DD8-B1B0-521401F43097.png

4、清空Launch Screen File


72CB1773-D0F9-4466-814D-91DC7FA24454.png

5、加入版本号的代码

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
    
    [self customLaunchImageView];

    return YES;
}
- (void)customLaunchImageView
{
    UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
    launchImageView.image = [self getLaunchImage];
    [self.window addSubview:launchImageView];
    [self.window bringSubviewToFront:launchImageView];
    
    UILabel *vesionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 260, 100, 30)];
    vesionLabel.backgroundColor = [UIColor cyanColor];
    //获取当前设备中应用的版本号
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    vesionLabel.text = [NSString stringWithFormat:@"V %@",currentVersion];
    vesionLabel.textAlignment = NSTextAlignmentCenter;
    [launchImageView addSubview:vesionLabel];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:1.2 animations:^{
            launchImageView.alpha = 0.0;
            launchImageView.transform = CGAffineTransformMakeScale(1.2, 1.2);
        } completion:^(BOOL finished) {
            [launchImageView removeFromSuperview];
        }];
    });
}

- (UIImage *)getLaunchImage
{
    UIImage *lauchImage = nil;
    NSString *viewOrientation = nil;
    CGSize viewSize = [UIScreen mainScreen].bounds.size;
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        
        viewOrientation = @"Landscape";
        
    } else {
        
        viewOrientation = @"Portrait";
    }
    
    NSArray *imagesDictionary = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for (NSDictionary *dict in imagesDictionary) {
        
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            
            lauchImage = [UIImage imageNamed:dict[@"UILaunchImageName"]];
        }
    }
    return lauchImage;
}

运行结果:

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

推荐阅读更多精彩内容

  • 现在好像一种方法不能全部适配ios7、ios8、ios9 一、第一种(可以实现) (改项目b id 和版本) ...
    红酒佳坊阅读 8,727评论 1 6
  • iOS启动页其实很简单 只要设置正确 尺寸格式正确就可以正常显示的 Step1 1.点击Image.xcasset...
    默默的前行阅读 1,652评论 10 1
  • iOS启动页其实很简单 只要设置正确 尺寸格式正确就可以正常显示 Step1 1.点击Image.xcassets...
    漫雪思舟阅读 4,917评论 1 1
  • 煦风拂柳 吹打在脸颊 泛起阵阵涟漪 一场金贵的春雨淅淅沥沥 打湿了我的心房 温润着尘世 划破夜空的静寂 却滋养了你...
    吴枫WF阅读 123评论 0 0
  • 视频unit1-3,音频oa循环,中文绘本,身边的数字,霍加叔叔和他的100只猫,英文绘本,hello ,bubb...
    piedmontite阅读 158评论 0 0