gpt4 book ai didi

swift - 如何使用struct在swift中显示UIImage

转载 作者:行者123 更新时间:2023-11-30 13:07:22 26 4
gpt4 key购买 nike

我在使用 UIImage 时遇到问题,我正在尝试将图像显示到 ImageView 中,但我在结构方面遇到问题...有人可以帮助我吗,这是我的代码。

import UIKit

struct Question {
var Question: String!
var Answers: [String]!
var Answer: Int!
var Img: UIImage?
}

class ViewController: UIViewController {

@IBOutlet weak var questionLabel: UILabel!
@IBOutlet var Buttons: [UIButton]!
@IBOutlet weak var imgView: UIImageView! //This part Im pretty sure that i need to connect to the var Img:UIImage? but Im not sure how?

//Creation of a variable to hold the Quesitons,Question Number and Answer Number

var Questions = [Question]()
var questionNumber = Int()
var answerNumber = Int()

override func viewDidLoad() {
super.viewDidLoad()
//Creation of the Question
Questions = [Question(Question: "Who is this guy?", Answers: ["Alex","Roberto","Joey","Will"], Answer: 2, Img: UIImage.self(named:"steve_jobs"))]

//We call our funciton into the viewDidLoad
pickQuestion()
}

最佳答案

使用结构体中的图像来设置 UIImageView 的图像属性:

imgView.image = Questions[questionNumber].Img

关于swift - 如何使用struct在swift中显示UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39180139/

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