【发布时间】:2020-07-26 18:25:56
【问题描述】:
我遵循了类似question's 答案的确切代码,虽然它为他们垂直滚动,但对我来说却不是。代码中的标签只是一个测试,实际程序中还有更多的标签,但它们是稍后从 firebase 添加的,所以我不确定这是否会改变任何东西。虽然这不是超级重要,但我更愿意以编程方式解决这个问题,因为我在该领域更有能力。我不擅长提问或提供正确的代码,所以整个项目是here
`
@IBOutlet weak var history: UIStackView!
@IBOutlet weak var scrollView: UIScrollView!
var ref: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
ref = Database.database().reference()
let label = UILabel(frame: CGRect.init())
label.text = "Label"
history.addArrangedSubview(label)
scrollView.contentSize = CGSize(width: view.bounds.width, height: view.bounds.height)
history.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true
history.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor).isActive = true
history.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
history.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
history.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
//history.heightAnchor.constraint(lessThanOrEqualTo: scrollView.heightAnchor).isActive = true
scrollView.addSubview(history)
view.addSubview(scrollView)
`
【问题讨论】:
标签: swift xcode uiscrollview uistackview