gpt4 book ai didi

ios - 随机图像核心-点击按钮时显示背景

转载 作者:行者123 更新时间:2023-11-28 13:16:11 25 4
gpt4 key购买 nike

我试图在点击按钮时生成随机图像,但是当我点击按钮时,两个图像都消失了,只有背景出现了。

这是我的代码:

@IBAction func PickerTapped(sender: UIButton) {

//randomize a number for the first image

var firstrandomNumber = arc4random_uniform(7) + 1

//construct a string with a random number

var firstLeftHandImageString: String = String(format: "rud%i", firstrandomNumber)

// set the left hand image view to the asset corresponding to the randomized number

self.LeftHandImageView.image = UIImage(named: "firstLeftHandImageString")

//randomize a number for the second image

var secondrandomNumber = arc4random_uniform(7) + 1

//construct a string with a random number

var secondRightHandImageString: String = String(format: "rud%i", secondrandomNumber)

//set the right hand image view to the asset corresponding to the randomized number

self.RightHandImageView.image = UIImage(named: "secondRightHandImageString")
}

最佳答案

self.RightHandImageView.image = UIImage(named: "secondRightHandImageString")

从名为“secondRightHandImageString”的 Assets 创建图像

如果你想用你生成的字符串创建一个图像,你需要(注意变量名周围没有双引号)

self.RightHandImageView.image = UIImage(named: secondRightHandImageString)

关于ios - 随机图像核心-点击按钮时显示背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28952759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com