Random Image for Launch Screen

耗尽温柔 提交于 2019-12-06 08:42:53

问题


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

I've added a UIImageView in the Launchscreen.storyboard

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")      }

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


回答1:


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

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> 


来源:https://stackoverflow.com/questions/38535742/random-image-for-launch-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!