以编程方式位于底部的按钮

Tib*_*iaZ 2 uibutton ios swift

我正在尝试使用这个库:

https://github.com/yannickl/DynamicButton#requirements

我需要以编程方式(Swift)将底部放在 ViewController 的底部,底部和按钮之间有一点距离。我该怎么办呢?

Phy*_*ber 6

使用自动布局

self.view.addSubview(button)

button.translatesAutoresizingMaskIntoConstraints = false

button.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
button.widthAnchor.constraint(equalToConstant: 50).isActive = true
button.heightAnchor.constraint(equalToConstant: 50).isActive = true
button.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -20).isActive = true
Run Code Online (Sandbox Code Playgroud)