gpt4 book ai didi

ios - 尝试以编程方式将 UIScrollView 添加到我的应用程序中,但我不断收到空白 View

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

尝试创建一个 UIScrollView,但我似乎无法让我的标 checkout 现,因为我希望它们位于正中心。

lazy var label : UILabel = {
let label = UILabel()
label.text = "center of container view.center of container view"
label.font = UIFont(name: "Bebas Neue", size: 23)!
label.textColor = .black
return label
}()
// Mark: Properties

lazy var contentViewSize = CGSize(width: self.view.frame.width + 1200, height: self.view.frame.height)

// Mark: Views
fileprivate lazy var parentScrollView : UIView = {
var newView = UIView()

newView.translatesAutoresizingMaskIntoConstraints = false
newView.backgroundColor = .black
newView.frame = self.scrollView.bounds
newView.frame.size = contentViewSize


return newView
}()
fileprivate lazy var scrollView : UIScrollView = {
var uiScrollView = UIScrollView(frame: .zero)
uiScrollView.translatesAutoresizingMaskIntoConstraints = false
uiScrollView.frame = view.bounds
uiScrollView.backgroundColor = .gray
uiScrollView.addViewBorder(borderColor: UIColor.gray.cgColor, borderWith: 10, borderCornerRadius: 0)
// uiScrollView.alpha =
uiScrollView.contentSize = contentViewSize
// uiScrollView.autoresizingMask = .flexibleHeight
uiScrollView.showsVerticalScrollIndicator = true
uiScrollView.bounces = true

return uiScrollView
}()
fileprivate lazy var tutorialView : UIStackView = {

var tutView = UIStackView(arrangedSubviews: [label,label,label])
tutView.axis = .horizontal
tutView.backgroundColor = .white
tutView.distribution = .fillEqually
tutView.spacing = 0


return tutView
}()
override func viewDidLoad() {

view.backgroundColor = .white

view.addSubview(scrollView)
scrollView.addSubview(parentScrollView)
parentScrollView.addSubview(tutorialView)

scrollView.widthAnchor.constraint(equalTo:self.view.widthAnchor,multiplier: 0.9).isActive = true
scrollView.heightAnchor.constraint(equalTo:self.view.heightAnchor,multiplier: 0.7).isActive = true
scrollView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
scrollView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 75).isActive = true

tutorialView.topAnchor.constraint(equalTo: parentScrollView.topAnchor,constant: +10).isActive = true}

似乎当我使用 topAnchor 添加最后一个 constraight 时,我得到了一个空白屏幕。当我把它取下来时,我实际上得到了两个 View 之间的边界,并且我可以进行一些滚动。任何帮助,将不胜感激。谢谢

最佳答案

你给scrollView赋值了吗?

 uiScrollView.contentSize.width = 1200

然后给tutorialView设置与其他约束相同的宽度约束。

 NSLayoutConstraint.activate([
tutorialView.widthAnchor.constraint(equalToConstant: 1200),
tutorialView.heightAnchor.constraint(equalTo: uiScrollView.heightAnchor)
])

关于ios - 尝试以编程方式将 UIScrollView 添加到我的应用程序中,但我不断收到空白 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59975270/

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