Няма описание

KXLaunchImageView.m 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KXLaunchImageView.m
  3. // CAISHEN
  4. //
  5. // Created by kuxuan on 2017/8/17.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXLaunchImageView.h"
  9. @implementation KXLaunchImageView
  10. #pragma mark - CustomAccessors
  11. - (instancetype)initWithFrame:(CGRect)frame {
  12. if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
  13. self.userInteractionEnabled = YES;
  14. self.image = [self launchImage];
  15. }
  16. return self;
  17. }
  18. #pragma mark - Private
  19. /**
  20. 获取启动图
  21. @return 启动图
  22. */
  23. - (UIImage *)launchImage {
  24. UIImage *imagePortrait = [self launchImageWithType:@"Portrait"];
  25. if(imagePortrait) {
  26. return imagePortrait;
  27. }
  28. UIImage *imageLandscape = [self launchImageWithType:@"Landscape"];
  29. if(imageLandscape) {
  30. return imageLandscape;
  31. }
  32. NSLog(@"获取LaunchImage失败!请检查是否添加启动图,或者规格是否有误.");
  33. return nil;
  34. }
  35. /**
  36. 通过图片方向获取启动图
  37. @param type 图片方向
  38. @return 启动图
  39. */
  40. - (UIImage *)launchImageWithType:(NSString *)type {
  41. CGSize screenSize = [UIScreen mainScreen].bounds.size;
  42. NSString *viewOrientation = type;
  43. NSString *launchImageName = nil;
  44. NSArray<NSDictionary *> *imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
  45. for (NSDictionary *dict in imagesDict) {
  46. CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
  47. if([viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
  48. if([dict[@"UILaunchImageOrientation"] isEqualToString:@"Landscape"]) {
  49. imageSize = CGSizeMake(imageSize.height, imageSize.width);
  50. }
  51. if(CGSizeEqualToSize(imageSize, screenSize)) {
  52. launchImageName = dict[@"UILaunchImageName"];
  53. UIImage *image = [UIImage imageNamed:launchImageName];
  54. return image;
  55. }
  56. }
  57. }
  58. return nil;
  59. }
  60. @end