我已将以下代码添加到我的 UIViewController 中:
override func viewDidLoad() {
super.viewDidLoad()
viewBrochures.isUserInteractionEnabled = true
let brochure1: UIImageView = UIImageView(image: UIImage(named: "image1")!)
brochure1.translatesAutoresizingMaskIntoConstraints = false
brochure1.contentMode = .scaleAspectFit
brochure1.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 400)
viewBrochures.addSubview(brochure1)
let brochure2: UIImageView = UIImageView(image: UIImage(named: "image2")!)
brochure2.translatesAutoresizingMaskIntoConstraints = false
brochure2.contentMode = .scaleAspectFit
brochure2.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 400)
viewBrochures.addSubview(brochure2)
let brochure3: UIImageView = UIImageView(image: UIImage(named: "image3")!)
brochure3.translatesAutoresizingMaskIntoConstraints = false
brochure3.contentMode = .scaleAspectFit
brochure3.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, …Run Code Online (Sandbox Code Playgroud)