屏幕上没有出现图像视图

问题描述

我正在尝试将背景图像添加到我的屏幕上并设置一些约束,但是不幸的是,该图像视图没有出现,我也不知道是什么原因。我检查了图像文件是否在项目文件夹中。

import UIKit

class ViewController: UIViewController {

    let backgroundImageView = UIImageView()

    override func viewDidLoad() {
       super.viewDidLoad()
       setBackground()
    }

    func setBackground() {
        view.addSubview(backgroundImageView)
        backgroundImageView.translatesAutoresizingMaskIntoConstraints = false
        backgroundImageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        backgroundImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        backgroundImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        backgroundImageView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        backgroundImageView.image = UIImage(named: "background-test-image")
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)