我想使用这个库:按钮底部编程
https://github.com/yannickl/DynamicButton#requirements
,我需要把底部编程(SWIFT)在我的ViewController的底部与底部之间有点距离的和按钮。我怎么能这样做?
非常感谢!
我想使用这个库:按钮底部编程
https://github.com/yannickl/DynamicButton#requirements
,我需要把底部编程(SWIFT)在我的ViewController的底部与底部之间有点距离的和按钮。我怎么能这样做?
非常感谢!
使用自动布局
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
您必须首先将子视图添加到您的视图中 – Phyber
完美的伴侣,一如既往的好,乐于助人!十分感谢! –
let bottomOffset = 20
let yourButton = UIButton(frame: CGRect(X:0, y:0, width:50, height:50))
yourButton.backgroundColor = UIColor.red
yourButton.frame.origin = CGPoint(X:0, y:self.view.framse.size.height - yourButton.frame.size.height - bottomOffset)
self.view.addsubview(yourButton)
使用约束 – Phyber
不明白为什么我收到了3张反对票? –