欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

用iOS代码获取APP启动页图片

程序员文章站 2023-12-13 08:09:22
用代码获取app启动页图片  // // applesystemservice.swift // swift-animations // /...

用代码获取app启动页图片 

//
// applesystemservice.swift
// swift-animations
//
// created by youxianming on 16/8/11.
// copyright © 2016年 youxianming. all rights reserved.
//

import uikit

class applesystemservice : nsobject {
 
 /**
  get the lauch image.
  
  - returns: the lauch image.
  */
 class func launchimage() -> uiimage {
  
  var lauchimage  : uiimage!
  var vieworientation : string!
  let viewsize  = uiscreen.mainscreen().bounds.size
  let orientation  = uiapplication.sharedapplication().statusbarorientation
  
  if orientation == .landscapeleft || orientation == .landscaperight {
   
   vieworientation = "landscape"
   
  } else {
   
   vieworientation = "portrait"
  }
  
  let imagesinfoarray = nsbundle.mainbundle().infodictionary!["uilaunchimages"]
  for dict : dictionary <string, string> in imagesinfoarray as! array {
   
   let imagesize = cgsizefromstring(dict["uilaunchimagesize"]!)
   if cgsizeequaltosize(imagesize, viewsize) && vieworientation == dict["uilaunchimageorientation"]! as string {
    
    lauchimage = uiimage(named: dict["uilaunchimagename"]!)
   }
  }
  
  return lauchimage
 }
}

源码 - objective-c 

//
// applesystemservice.h
// applesystemservice
//
// created by youxianming on 16/7/2.
// copyright © 2016年 youxianming. all rights reserved.
//

#import <foundation/foundation.h>
#import <uikit/uikit.h>

@interface applesystemservice : nsobject

/**
 * get the lauch image.
 *
 * @return the lauch image.
 */
+ (uiimage *)launchimage;

@end



//
// applesystemservice.m
// applesystemservice
//
// created by youxianming on 16/7/2.
// copyright © 2016年 youxianming. all rights reserved.
//

#import "applesystemservice.h"

@implementation applesystemservice

+ (uiimage *)launchimage {

 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;
}

@end

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: