1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // KXLaunchImageView.m
- // CAISHEN
- //
- // Created by kuxuan on 2017/8/17.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXLaunchImageView.h"
- @implementation KXLaunchImageView
- #pragma mark - CustomAccessors
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
-
- self.userInteractionEnabled = YES;
- self.image = [self launchImage];
- }
-
- return self;
- }
- #pragma mark - Private
- /**
- 获取启动图
-
- @return 启动图
- */
- - (UIImage *)launchImage {
-
- UIImage *imagePortrait = [self launchImageWithType:@"Portrait"];
- if(imagePortrait) {
- return imagePortrait;
- }
-
- UIImage *imageLandscape = [self launchImageWithType:@"Landscape"];
- if(imageLandscape) {
- return imageLandscape;
- }
-
- NSLog(@"获取LaunchImage失败!请检查是否添加启动图,或者规格是否有误.");
-
- return nil;
- }
- /**
- 通过图片方向获取启动图
-
- @param type 图片方向
- @return 启动图
- */
- - (UIImage *)launchImageWithType:(NSString *)type {
-
- CGSize screenSize = [UIScreen mainScreen].bounds.size;
- NSString *viewOrientation = type;
- NSString *launchImageName = nil;
-
- NSArray<NSDictionary *> *imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
- for (NSDictionary *dict in imagesDict) {
-
- CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
-
- if([viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
-
- if([dict[@"UILaunchImageOrientation"] isEqualToString:@"Landscape"]) {
- imageSize = CGSizeMake(imageSize.height, imageSize.width);
- }
-
- if(CGSizeEqualToSize(imageSize, screenSize)) {
- launchImageName = dict[@"UILaunchImageName"];
- UIImage *image = [UIImage imageNamed:launchImageName];
-
- return image;
- }
- }
- }
-
- return nil;
- }
- @end
|