我想使用這個庫:按鈕底部編程
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張反對票? –