gpt4 book ai didi

swift - 如何改变UIButton的位置?

转载 作者:行者123 更新时间:2023-11-30 10:14:54 25 4
gpt4 key购买 nike

什么也没发生,但为什么???

@IBOutlet weak var button10: UIButton!

override func viewDidLoad() {
super.viewDidLoad()

button10.center = CGPoint(x: self.view.frame.x/2, y: self.view.frame.y/2)

}

最佳答案

添加 View 中心约束

var constX = NSLayoutConstraint(item: button10, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
view.addConstraint(constX)

var constY = NSLayoutConstraint(item: button10, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)
view.addConstraint(constY)

关于swift - 如何改变UIButton的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30728507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com