gpt4 book ai didi

ios - 快速/重构

转载 作者:行者123 更新时间:2023-11-28 11:10:11 25 4
gpt4 key购买 nike

我正在创建一个 View 以将其用作 viewDidLoad 中的 subview 。

    override func viewDidLoad() {
let backgroundView = UIView()
backgroundView.translatesAutoresizingMaskIntoConstraints = false
backgroundView.backgroundColor = UIColor.blackColor()

let viewsDictionary = ["backgroundView":backgroundView]

let backgroundView_constraint_H = NSLayoutConstraint.constraintsWithVisualFormat(
"H:[backgroundView(10000)]",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil, views: viewsDictionary)
let backgroundView_constraint_V = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[backgroundView(10000)]",
options: NSLayoutFormatOptions(rawValue:0),
metrics: nil, views: viewsDictionary)

backgroundView.addConstraints(backgroundView_constraint_H)
backgroundView.addConstraints(backgroundView_constraint_V)

backgroundView.alpha = 0.9

self.tableView.backgroundView = backgroundView
}

将所有代码放入自己的 .swift 文件并仅在 viewDidLoad 调用 self.tableView.backgroundView = backgroundView 的正确解决方法是什么?

非常感谢您的帮助。

最佳答案

        class func backgroundView()->UIView {
let backgroundView = UIView()
backgroundView.translatesAutoresizingMaskIntoConstraints = false
backgroundView.backgroundColor = UIColor.blackColor()
backgroundView.frame = self.tableView.frame
backgroundView.alpha = 0.9

self.tableView.backgroundView = backgroundView

关于ios - 快速/重构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35601254/

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