启动屏幕的随机图像

启动屏幕的随机图像

本文介绍了启动屏幕的随机图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个不同的图像我想使用Launch Screen。

I have 3 different images I'd like to use Launch Screen.

我添加了 UIImageView Launchscreen.storyboard

我以为我可以使用带随机函数的简单Switch语句来选择图像:

And I was thinking I could use a simple Switch statement with a randomizer to select the image:

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 将无效。

However I'm not really sure where to implement the code as the viewDidLoad will not work.

推荐答案

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

You can set the UILaunchImageFile by a relative path and then put an image at the path and use your random.

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

For example you change the launchscreen after launching by setting UILaunchImageFile property in the info.plist. You would then write a random image to the Documents folder.

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

这篇关于启动屏幕的随机图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:57