Reputation: 750
I am trying to use this library:
https://github.com/yannickl/DynamicButton#requirements
And I need to put the bottom programmatically (Swift) on the bottom of my ViewController with a bit of distance between the bottom and the button. How could I do it ?
Upvotes: 2
Views: 7308
Reputation: 2099
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.frame.size.height - yourButton.frame.size.height - bottomOffset)
self.view.addsubview(yourButton)
Upvotes: 4
Reputation: 1368
Using auto-layout
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
Upvotes: 6