我遇到UIImage的问题,我试图在图像视图中显示和图像,但我的结构有问题......有人可以帮助我这里是我的代码。
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()
}
答案 0 :(得分:0)
使用struct中的图像来设置UIImageView的图像属性:
imgView.image = Questions[questionNumber].Img