gpt4 book ai didi

ios - 使用 snapkit 创建两个 uiview 的约束

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

我正在底部创建一个 UIView,静态高度为 60,然后在顶部创建一个填充其余部分。然而这段代码似乎只是让顶部的代码填满了整个屏幕。

    //bottomWrapperView
let bottomWrapperView = UIView()
bottomWrapperView.backgroundColor = UIColor.red
self.addSubview(bottomWrapperView)

//TopWrapperView
let topWrapperView = UIView()
topWrapperView.backgroundColor = UIColor.green
self.addSubview(topWrapperView)


//BottomWrapperView Constraints
bottomWrapperView.snp.makeConstraints { (make) -> Void in
make.height.equalTo(60)
make.left.equalTo(self).offset(0)
make.bottom.equalTo(self).offset(0)
make.right.equalTo(self).offset(0)
make.top.equalTo(topWrapperView)
}



//TopWrapperView Constraints
topWrapperView.snp.makeConstraints { (make) -> Void in

make.left.equalTo(self).offset(0)
make.top.equalTo(self).offset(0)
make.bottom.equalTo(bottomWrapperView)
make.right.equalTo(self).offset(0)
}

最佳答案

这里,您需要使 topWrapperView 的底部约束等于 bottomWrapperView 的顶部

//BottomWrapperView Constraints
bottomWrapperView.snp.makeConstraints { (make) -> Void in
make.height.equalTo(60)
make.left.equalTo(self).offset(0)
make.bottom.equalTo(self).offset(0)
make.right.equalTo(self).offset(0)
}

//TopWrapperView Constraints
topWrapperView.snp.makeConstraints { (make) -> Void in
make.left.equalTo(self).offset(0)
make.top.equalTo(self).offset(0)
make.bottom.equalTo(bottomWrapperView.snp.top)
make.right.equalTo(self).offset(0)
}

关于ios - 使用 snapkit 创建两个 uiview 的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40322522/

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