ios - 启动屏幕的随机图像

标签 ios swift launch-screen

我有 3 张不同的图像,我想使用启动屏幕。

我在 Launchscreen.storyboard 中添加了一个 UIImageView

我想我可以使用带有随机发生器的简单 Switch 语句来选择图像:

var random = arc4random_uniform(3) //returns 0 to 2 randomly

  switch random {
    case 0:
        launchImageView.image = UIImage(named: "splash1.jpg")
    case 1:
        myImageView.image = UIImage(named: "splash2.jpg")
    default:
        /myImageView.image = UIImage(named: "splash3.jpg")      }

但是我不太确定在哪里实现代码,因为 viewDidLoad 将不起作用。

最佳答案

您可以通过相对路径设置UILaunchImageFile,然后将图像放在该路径并使用您的随机。

例如,您在启动后通过在 info.plist 中设置 UILaunchImageFile 属性来更改启动屏幕。然后,您可以将随机图像写入 Documents 文件夹。

<key>UILaunchImageFile</key>
<string>../Documents/image.png</string> 

关于ios - 启动屏幕的随机图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38535742/

相关文章:

ios - 如何为调试和发布构建 Xcode IOS 编写不同的脚本

swift - UICollectionViewDelegateFlowLayout 不更改单元格边界

ios - 启动屏幕上用户定义的运行时属性

ios - 如果在 LaunchScreen.storyboard 上使用该图像,图像在更改时不会更新

cordova - Meteor:在移动 Cordova 上等待热代码推送期间按住启动屏幕

ios - EKEventStore eventWithIdentifier 导致 EKCADErrorDomain 错误 1010

ios - 为弹出 View Controller 创建一个 NIB 文件

ios - 为 UIAlertAction 编写处理程序

ios - 如何从 `Any` 类型访问某些对象?

Swift 3 在 For 循环中排除项目