ios - 图像视图未出现在屏幕上
问题描述
我正在尝试将背景图像添加到我的屏幕上并设置一些约束,但不幸的是图像视图没有出现,我不知道原因是什么。我检查了图像文件是否在项目文件夹中。
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")
}
}
解决方案
推荐阅读
- c# - 如何搜索在 MVC EF 中工作的 int 条目?
- javascript - 在 ExtJS 3.4 中更改工具的持续时间
- nightmare - Nightmarejs 不在服务器上呈现 javascript
- tree - 在 Lisp 中逐级遍历树(广度优先)
- npm - NPM 挂起并卡在发布/打包上
- google-analytics - 谷歌分析服务器端归因和 gclid,它是如何工作的?
- python - 错误处理问题,似乎无法识别错误
- java - 在向用户显示随机对象时使用访问器方法?
- r - 有效地组合跨越相同范围的多个 irange(保留 mcols)
- javascript - 使用自动播放来播放使用 HTML5 音频的广播电台