背景:由于发展需要,老项目加隐私政策和用户协议并且在第一次启动时提示用户,等都开发完发现页面背景少点啥,那就启动图显示在那城吧。
启动图在launchimage文件夹中,于是网上搜索得到object-c版本,搬个砖翻译成swift版本,代码如下:
static func getLaunchImage() -> String? {
let orientation = "Portrait" //我的项目只能是竖屏,如果其他请换名自行实现
let screenSize = UIScreen.main.bounds.size
var launchImageName:String?
if let arr = Bundle.main.infoDictionary?["UILaunchImages"] as? [[String:Any]] {
for item in arr {
guard let imageSize = item["UILaunchImageSize"] as? String else { continue }
guard let imageOrientation = item["UILaunchImageOrientation"] as? String else { continue }
let size = NSCoder.cgSize(for: imageSize);
if size == screenSize && orientation == imageOrientation {
launchImageName = item["UILaunchImageName"] as? String
break
}
}
}
return launchImageName
}
网友评论