Snapkit,将UILabel粘到底部

时间:2018-04-02 01:26:18

标签: ios swift snapkit

我有一个内部有几个元素的scrollview。我必须将底部标签设置为粘贴在视图的底部,无论如何但不应与屏幕较小时发生的视图重叠。

如何在Snapkit中实现这一目标?

1 个答案:

答案 0 :(得分:1)

斯威夫特4:

someScrollView.translatesAutoresizingMaskIntoConstraints = false

let stickyLabel = UILabel()
stickyLabel.backgroundColor = UIColor.red
stickyLabel.translatesAutoresizingMaskIntoConstraints = false
stickyLabel.text = "some sticky bottom label"
self.view.addSubview(stickyLabel)

someScrollView.snp.makeConstraints { (make) -> Void in
    make.top.leading.trailing.equalToSuperview()
}

stickyLabel.snp.makeConstraints { (make) -> Void in
    make.top.equalTo(someScrollView.snp.bottom).offset(4)
    make.leading.equalToSuperview().offset(4)
    make.bottom.trailing.equalToSuperview().offset(-4)
}

会给出类似的东西:

sticky bottom view