我有2个按钮,然后隐藏其中一个按钮,我想将另一个按钮移到该按钮的位置。
我想问一下有约束条件且没有约束条件的变量。
我该怎么做?
像下面的代码一样设置一个按钮。
func setupButton() {
button = UIButton(type: UIButtonType.system)
// SIZE
button.bounds = CGRect(x: 0, y: 0, width: view.bounds.width / 2, height: 50)
// POSITION
button.center = CGPoint(x: view.bounds.width / 2, y: 200)
// BACKGOUND COLOUR
button.backgroundColor = UIColor.lightGray
// CORNER RADIUS
button.layer.cornerRadius = 5
// TEXT COLOUR
button.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
// SET TEXT
button.setTitle("press me", for: UIControlState.normal)
// SET FONT SIZE
button.titleLabel!.font = UIFont.systemFont(ofSize: 17)
// BUTTON FUNCTION
button.addTarget(self, action: #selector(ViewController.buttonPressed(_:)), for: UIControlEvents.touchUpInside)
// ADD BUTTON TO VIEW
view.addSubview(button)
}
然后,您可以将其隐藏在buttonPressed函数中,也可以在buttonPressed中设置新按钮。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句